Sunday, September 04, 2016

In
multi-threaded applications, many a times during debugging or logging, we wish
to identify the threads by name[functionality ]. Simply printing the executing
method name in logs does not help if the functions are common between threads
doing different tasks. Also you may want to see the currently running threads
from either top or ps in your application.

Here
is sample program to tag your threads with proper names. Use prctl defined in <sys/prctl.h> , to get/set thread names. Keep in mind that the
name can be up to 16 bytes long only.