---
name: "pthread_attr_get_np"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/pthread_attr_get_np"
---

# pthread\_attr\_get\_np(3)

get attributes of an existing thread

## NAME

**pthread\_attr\_get\_np** – get attributes of an existing thread

## LIBRARY

POSIX Threads Library (libpthread, -lpthread)

## SYNOPSIS

**#include \<pthread\_np.h\>**

*int*\

**pthread\_attr\_get\_np**(*pthread\_t pid*, *pthread\_attr\_t \*dst*);

## DESCRIPTION

The **pthread\_attr\_get\_np**() function is used to retrieve the attributes of the specified thread into an existing *pthread\_attr\_t* structure. The attributes' values are the current ones for the target thread, except for the stack top address if not properly aligned for the architecture, since in this case its value has been adjusted internally before use.

Argument *dst* must be a pointer to a valid attributes object( it was initialized at some point by [pthread\_attr\_init(3)](/pthread_attr_init/3.md) and was not destroyed since then). After a successful call to **pthread\_attr\_get\_np**(), the individual attributes' values can be retrieved as usual via the corresponding accessor functions as documented in [pthread\_attr(3)](/pthread_attr/3.md). After a failed call to **pthread\_attr\_get\_np**(), the object pointed to by *dst* is left unmodified, and can continue to be used as if the failed call never happened.

## RETURN VALUES

If successful, **pthread\_attr\_get\_np**() function returns 0. Otherwise, an error number is returned to indicate the error.

## EXAMPLES

This function retrieves the stack size of the thread specified by the *pid* argument:

```
size_t
my_thread_stack_size(pthread_t tid)
{
	pthread_attr_t attr;
	size_t size;
	pthread_attr_init(&attr);
	pthread_attr_get_np(tid, &attr);
	pthread_attr_getstacksize(&attr, &size);
	pthread_attr_destroy(&attr);
	return (size);
}
```

## ERRORS

The **pthread\_attr\_get\_np**() function will fail if:

- \[EINVAL\]

  One of the arguments has an invalid value.

- \[ESRCH\]

  No thread could be found corresponding to that specified by the given thread ID.

- \[ENOMEM\]

  There was not enough memory to allocate additional storage needed by the attributes object's implementation.

## SEE ALSO

[pthread\_attr(3)](/pthread_attr/3.md), [pthread\_attr\_destroy(3)](/pthread_attr_destroy/3.md), [pthread\_attr\_getdetachstate(3)](/pthread_attr_getdetachstate/3.md), [pthread\_attr\_getinheritsched(3)](/pthread_attr_getinheritsched/3.md), [pthread\_attr\_getschedparam(3)](/pthread_attr_getschedparam/3.md), [pthread\_attr\_getschedpolicy(3)](/pthread_attr_getschedpolicy/3.md), [pthread\_attr\_getscope(3)](/pthread_attr_getscope/3.md), [pthread\_attr\_getstack(3)](/pthread_attr_getstack/3.md), [pthread\_attr\_getstackaddr(3)](/pthread_attr_getstackaddr/3.md), [pthread\_attr\_getstacksize(3)](/pthread_attr_getstacksize/3.md), [pthread\_attr\_init(3)](/pthread_attr_init/3.md), [pthread\_np(3)](/pthread_np/3.md)

## AUTHORS

The **pthread\_attr\_get\_np**() function and this manual page were written by Alexey Zelkin ⟨*phantom@FreeBSD.org*⟩, and the latter was revised by Olivier Certner ⟨*olce@FreeBSD.org*⟩.
