OpenBSD manual page server

Manual Page Search Parameters

GETTHRNAME(2) System Calls Manual GETTHRNAME(2)

getthrname, setthrnameget or set thread name

#include <unistd.h>

int
getthrname(pid_t tid, char *name, size_t namelen);

int
setthrname(pid_t tid, const char *name);

The () system call stores the name of tid, a thread in the current process, into the buffer name, which must be of at least namelen bytes long. The buffer should be at least _MAXCOMLEN bytes long. The () system call sets the name of tid to the supplied name. The name will be silently truncated to _MAXCOMLEN - 1 bytes. For both functions, if tid is zero then the current thread is operated on.

Thread names have no inherent meaning in the system and are intended for display and debugging only. They are not secret but rather are visible to other processes using sysctl(2) or kvm_getprocs(3) and in ps -H output.

After execve(2), the name of the process's only thread is reset to the empty string. Similarly, additional threads created with __tfork(3) start with the empty name. After fork(2), the new process's only thread has the same name as the thread that invoked fork(2).

Upon successful completion, the value 0 is returned; otherwise the error number is returned.

getthrname() and setthrname() will succeed unless:

[]
The name argument points to an invalid address.
[]
The thread tid does not exist.

In addition, getthrname() may return the following error:

[]
The value of namelen is not large enough to store the thread name and a trailing NUL.

execve(2), fork(2), sysctl(2), __tfork(3), kvm_getprocs(3), pthread_get_name_np(3), pthread_set_name_np(3)

The getthrname() and setthrname() system calls are specific to OpenBSD; pthread_get_name_np(3) and pthread_set_name_np(3) operate on the same thread name in a more portable way.

The getthrname() and setthrname() system calls first appeared in OpenBSD 7.3.

OpenBSD-current June 12, 2026 GETTHRNAME(2)