Anonym Anonym - 2 years ago 93
Linux Question

Can I set the name of a thread in pthreads/Linux?

Is there any way of setting the name of a thread in Linux?

My main purpose is it would be helpful while debugging, and also nice if that name was exposed through e.g.


Answer Source

Use the prctl(2) function with the option PR_SET_NAME (see the docs).

Note that the docs are a bit confusing. They say

Set the process name for the calling process

but since threads are light weight processes (LWP) on Linux, one thread is one process in this case.

You can see the thread name with ps -o cmd or in /proc/$PID/stat between the ():

4223 (kjournald) S 1 1 1 0...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download