.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH PTHREAD_SETNAME_NP 3 2015-07-23 "Linux" "Linux Programmer's Manual"
+.TH PTHREAD_SETNAME_NP 3 2019-03-06 "Linux" "Linux Programmer's Manual"
.SH NAME
pthread_setname_np, pthread_getname_np \- set/get the name of a thread
.SH SYNOPSIS
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\\0\(aq).
+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;
.I name
specifies the new name.
-
+.PP
The
.BR pthread_getname_np ()
function can be used to retrieve the name of the thread.
.BR pthread_getname_np ()
T} Thread safety MT-Safe
.TE
-
+.sp 1
.SH CONFORMING TO
-These functions are nonstandard GNU extensions.
+These functions are nonstandard GNU extensions;
+hence the suffix "_np" (nonportable) in the names.
.SH NOTES
.BR pthread_setname_np ()
internally writes to the thread-specific
.IR /proc/self/task/[tid]/comm .
.BR pthread_getname_np ()
retrieves it from the same location.
-.SH EXAMPLE
+.SH EXAMPLES
.PP
The program below demonstrates the use of
.BR pthread_setname_np ()
and
.BR pthread_getname_np ().
-
+.PP
The following shell session shows a sample run of the program:
+.PP
.in +4n
-.nf
-
+.EX
.RB "$" " ./a.out"
Created a thread. Default name is: a.out
The thread name after setting it is THREADFOO.
a.out
.RB "$ " "cat /proc/5990/task/5991/comm"
THREADFOO
-.fi
+.EE
.in
.SS Program source
\&
-.nf
+.EX
#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#define NAMELEN 16
-#define errExitEN(en, msg) \\
- do { errno = en; perror(msg); exit(EXIT_FAILURE); \\
+#define errExitEN(en, msg) \e
+ do { errno = en; perror(msg); exit(EXIT_FAILURE); \e
} while (0)
static void *
if (rc != 0)
errExitEN(rc, "pthread_getname_np");
- printf("Created a thread. Default name is: %s\\n", thread_name);
+ printf("Created a thread. Default name is: %s\en", thread_name);
rc = pthread_setname_np(thread, (argc > 1) ? argv[1] : "THREADFOO");
if (rc != 0)
errExitEN(rc, "pthread_setname_np");
(argc > 2) ? atoi(argv[1]) : NAMELEN);
if (rc != 0)
errExitEN(rc, "pthread_getname_np");
- printf("The thread name after setting it is %s.\\n", thread_name);
+ printf("The thread name after setting it is %s.\en", thread_name);
rc = pthread_join(thread, NULL);
if (rc != 0)
errExitEN(rc, "pthread_join");
- printf("Done\\n");
+ printf("Done\en");
exit(EXIT_SUCCESS);
}
-.fi
+.EE
.SH SEE ALSO
.ad l
.nh