PTHREAD_SET_NAME_NP(3)
π PTHREAD_SET_NAME_NP(3) β the Library Functions Manual page, but make it cute
okay so bestie, we're in section 3 of the manual (that's the library functions one, iykyk) and today's main character is naming your threads. yes, your threads. they deserve names too π
β¨ NAME β¨
pthread_get_name_np, pthread_getname_np, pthread_set_name_np, pthread_setname_np β the whole "set and retrieve the thread name" situation, fr fr
π LIBRARY π
POSIX Threads Library β that's libpthread, and you link it with -lpthread. slay.
πΈ SYNOPSIS πΈ
#include <pthread_np.h>
void
pthread_get_name_np(pthread_t thread, char *name, size_t len);
int
pthread_getname_np(pthread_t thread, char *name, size_t len);
void
pthread_set_name_np(pthread_t thread, const char *name);
int
pthread_setname_np(pthread_t thread, const char *name);
look at all four of them. iconic lineup honestly π
π DESCRIPTION π
so pthread_set_name_np() and pthread_setname_np() both take the name you give them, make a copy of it, and stick that copy onto the thread you passed in. no cap, that's the whole vibe. π·οΈ
meanwhile pthread_get_name_np() and pthread_getname_np() are the reverse β they go fetch the name that's associated with thread and hand it back to you. and here's the little detail you need to know: if pthread_set_name_np() was never called for that thread before, the buffer that name points to will just be empty. not stale, not guessy β empty. periodt. π«
π¨ ERRORS π¨
pthread_getname_np and pthread_setname_np will fail β like actually return an error to you β if:
[ESRCH]β no thread could be found in the current process that corresponds to that thread IDthreadyou handed over. it's giving "who? never met her." π
and now for the plot twist: becausepthread_get_name_npandpthread_set_name_npare debugging-type functions, all errors that may appear inside them are silently ignored. not reported, not returned, not a peep. so don't expect them to tell you when something's off π
π SEE ALSO π
go read those too, bestie, cross-referencing is self care π
π STANDARDS π
pthread_set_name_np() and pthread_get_name_np() are non-standard extensions. and pthread_setname_np() and pthread_getname_np()? also non-standard β but a larger number of operating systems implement them, which lowkey means they're in fact more portable. the way that worked out πβ¨
ποΈ AUTHORS ποΈ
this manual page was written by Alexey Zelkin <phantom@FreeBSD.org> and Yuri Pankov <yuripv@yuripv.net>. thank you for your service π«Ά
and that's the tea, babes β this page came from Debian, dated October 12, 2021, and it's PTHREAD_SET_NAME_NP(3) forever and always. go name a thread after your bestie, she'll be so honored π
ππ¦
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms