diff options
Diffstat (limited to 'man3/pthread_setname_np.3')
-rw-r--r-- | man3/pthread_setname_np.3 | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/man3/pthread_setname_np.3 b/man3/pthread_setname_np.3 index 92de26913..5d9a711be 100644 --- a/man3/pthread_setname_np.3 +++ b/man3/pthread_setname_np.3 @@ -4,7 +4,7 @@ .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" -.TH pthread_setname_np 3 2023-02-05 "Linux man-pages 6.03" +.TH pthread_setname_np 3 2023-07-20 "Linux man-pages 6.05.01" .SH NAME pthread_setname_np, pthread_getname_np \- set/get the name of a thread .SH LIBRARY @@ -28,8 +28,9 @@ The function can be used to set a unique name for a thread, which can be useful for debugging multithreaded applications. -The thread name is a meaningful C language string, whose length is -restricted to 16 characters, including the terminating null byte (\[aq]\e0\[aq]). +The thread name is a meaningful C language string, +whose length is restricted to 16 characters, +including the terminating null byte (\[aq]\e0\[aq]). The .I thread argument specifies the thread whose name is to be changed; @@ -77,32 +78,30 @@ and is too small to hold the thread name. .PP If either of these functions fails to open -.IR /proc/self/task/[tid]/comm , +.IR /proc/self/task/ tid /comm , then the call may fail with one of the errors described in .BR open (2). -.SH VERSIONS -These functions were added in glibc 2.12. .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). -.ad l -.nh .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ +.na +.nh .BR pthread_setname_np (), .BR pthread_getname_np () T} Thread safety MT-Safe .TE -.hy -.ad .sp 1 .SH STANDARDS -These functions are nonstandard GNU extensions; +GNU; hence the suffix "_np" (nonportable) in the names. +.SH HISTORY +glibc 2.12. .SH NOTES .BR pthread_setname_np () internally writes to the thread-specific @@ -110,7 +109,7 @@ internally writes to the thread-specific file under the .I /proc filesystem: -.IR /proc/self/task/[tid]/comm . +.IR /proc/self/task/ tid /comm . .BR pthread_getname_np () retrieves it from the same location. .SH EXAMPLES @@ -150,47 +149,47 @@ THREADFOO #include <stdlib.h> #include <string.h> #include <unistd.h> - +\& #define NAMELEN 16 - +\& static void * threadfunc(void *parm) { sleep(5); // allow main program to set the thread name return NULL; } - +\& int main(int argc, char *argv[]) { pthread_t thread; int rc; char thread_name[NAMELEN]; - +\& rc = pthread_create(&thread, NULL, threadfunc, NULL); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_create"); - +\& rc = pthread_getname_np(thread, thread_name, NAMELEN); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_getname_np"); - +\& printf("Created a thread. Default name is: %s\en", thread_name); rc = pthread_setname_np(thread, (argc > 1) ? argv[1] : "THREADFOO"); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_setname_np"); - +\& sleep(2); - +\& rc = pthread_getname_np(thread, thread_name, NAMELEN); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_getname_np"); printf("The thread name after setting it is %s.\en", thread_name); - +\& rc = pthread_join(thread, NULL); if (rc != 0) errc(EXIT_FAILURE, rc, "pthread_join"); - +\& printf("Done\en"); exit(EXIT_SUCCESS); } |