Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change thread name on linux (htop)

Tags:

c

linux

pthreads

I have a multithread application and I would like that htop (as example) shows a different name per each thread running, at the moment what it shows is the "command line" used to run the main.

I have tried using

prctl(PR_SET_NAME, .....)

but it works only with top and with that call is only possible specify names up to 16 bytes.

I guess the trick is to modify the /proc/PID/cmdline content but that is a readonly field.

Anyone knows how to achieve it ?

like image 827
Gaetano Mendola Avatar asked Dec 16 '10 13:12

Gaetano Mendola


1 Answers

Since version 0.8.4, htop has an option: Show custom thread names

Press F2 and select the Display options menu. You should see:

htop custom thread names

like image 98
Drew Noakes Avatar answered Sep 22 '22 06:09

Drew Noakes