レナート   Wunschkonzert, Ponyhof und Abenteuerspielplatz   ﻟﻴﻨﺎﺭﺕ

Tue, 11 May 2010

Name Your Threads

Stefan Kost recently pointed me to the fact that the Linux system call prctl(PR_SET_NAME) does not in fact change the process name, but the task name (comm field) -- in contrast to what the man page suggests.

That makes it very useful for naming threads, since you can read back the name you set with PR_SET_NAME earlier from the /proc file system (/proc/$PID/task/$TID/comm on newer kernels, /proc/$PID/task/$TID/stat's second field on older kernels), and hence distuingish which thread might be responsible for the high CPU load or similar problems.

So, now go, if you have a project which involves a lot of threads, name them all individually, and make it easier to debug them. What's missing now, of course, is that gdb learns this and shows the comm name when doing info threads.

I have changed PulseAudio now to name all threads it creates.

Of course, what would be even better than this is full file system extended attribute support in procfs, so that we could attach arbitrary information to processes and threads, including references to .desktop files and such.

posted at: 01:22 | path: /projects | permanent link to this entry | 5 comments


Posted by john stultz at Tue May 11 03:25:58 2010
And don't forget, pthread_setname_np() and pthread_getname_np()!

Coming soon (hopefully) to a glibc near you!
http://repo.or.cz/w/glibc.git/commitdiff/86a4c67fb91b82c7b47c115b88ab01b1a696f10f

Posted by Mark Wielaard at Tue May 11 11:23:28 2010
GDB bugzilla for this idea:
http://sourceware.org/bugzilla/show_bug.cgi?id=8618

Posted by duffolonious at Sat May 22 20:33:17 2010
It appears to have been added in 2.6.33 (because it's not in 2.6.32 - unless it was added to a later stable patch, which I highly doubt).

Shucks.

Posted by duffolonious at Sat May 22 20:36:19 2010
Errr.. when did glibc add this functionality?

Posted by Tom Tromey at Fri Feb 4 21:54:14 2011
I added this to gdb CVS HEAD a little while ago.  Give it a try.

Leave a Comment:

Your Name:


Your E-mail (optional):


Comment:


As a protection against comment spam, please type the following number into the field on the right:
Secret Number Image

Please note that this is neither a support forum nor a bug tracker! Support questions or bug reports posted here will be ignored and not responded to!


It should be obvious but in case it isn't: the opinions reflected here are my own. They are not the views of my employer, or Ronald McDonald, or anyone else.

Please note that I take the liberty to delete any comments posted here that I deem inappropriate, off-topic, or insulting. And I excercise this liberty quite agressively. So yes, if you comment here, I might censor you. If you don't want to be censored your are welcome to comment on your own blog instead.


Lennart Poettering <mzoybt (at) 0pointer (dot) net>
Syndicated on Planet GNOME, Planet Fedora, planet.freedesktop.org, Planet Debian Upstream. feed RSS 0.91, RSS 2.0
Archives: 2005, 2006, 2007, 2008, 2009, 2010, 2011

Valid XHTML 1.0 Strict!   Valid CSS!