pthread_attr_get_np(3)

pthread_attr_get_np3

Get attributes of an existing thread

Usage

#include <pthread_np.h>

int

pthread_attr_get_np(pthread_t pid, pthread_attr_t *dst);

Library

POSIX Threads Library (libpthread, -lpthread)

Overview

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) 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). 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.

Releases

60 releases since FreeBSD 4.8-RELEASE; the text changed 39 times.

  1. 4.8–4.11
  2. 5.0
  3. 5.1–5.2.1
  4. 5.3–5.5
  5. 6.0–6.3
  6. 6.4
  7. 7.0
  8. 7.1
  9. 7.2
  10. 7.3
  11. 7.4
  12. 8.0
  13. 8.1
  14. 8.2
  15. 8.3
  16. 8.4
  17. 9.0
  18. 9.1
  19. 9.2
  20. 9.3
  21. 10.0
  22. 10.1
  23. 10.2
  24. 10.3
  25. 10.4
  26. 11.0
  27. 11.1
  28. 11.2
  29. 11.3
  30. 11.4
  31. 12.0
  32. 12.1
  33. 12.2
  34. 12.3
  35. 12.4
  36. 13.0
  37. 13.1–13.2
  38. 13.3–13.5
  39. 14.0
  40. 14.1–16.0

Authors

The pthread_attr_get_np() function and this manual page were written by Alexey Zelkin ⟨[email protected]⟩, and the latter was revised by Olivier Certner ⟨[email protected]⟩.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.