Question

I am trying to change the name of a thread in QNX 6.4.1, but the threads continue to be listed with the parent process name in a "pidin" listing.

I have created the thread:

iReturn = pthread_create(&threadhandle, &attr, &CALzoneCommThread, this);

I have renamed the thread from within the thread itself:

iReturn = pthread_setname_np(NULL, "HappyThread");

I have read the thread name back:

iReturn = pthread_getname_np(NULL, thread_name, 80);

And all threads return the name "HappyThread" as verified with printf statements, yet when I do a pidin, they are still listed with the process name "testapp". I need some help determining whether I have done something wrong in the code above, or if I am fundamentally misunderstanding the pidin command. Due to a requirement to play nicely with legacy utilities, the threads must have a name other than the process name.

Platform: QNX 6.4.1 Language: C

Was it helpful?

Solution

Yes, you have done something wrong in the code AND you are misunderstanding the output of the pidin command:

  1. The behavior of your code is unspecified because you are passing NULL (which gets converted to 0) as the thread-id. QNX numbers its threads from 1, therefore thread 0 is unspecified. Experimentation shows that passing 0 for the TID behaves identically to passing 1, for both pthread_setname_np and pthread_getname_np. Therefore, your code is setting and getting the ID of the main thread and not that of the thread you created via the pthread_create() call. You should pass threadhandle as the parameter of the set/get_name calls to actually refer to the newly created thread:

     iReturn = pthread_setname_np(threadhandle, "HappyThread");
     

  2. With no arguments pidin does not display the thread-name set via pthread_setname_np() at all. When called with no arguments pidin displays the process ID in the first column, the thread ID (numeric) in the second column and the name of the process in the third column (that's what you likely misunderstood for the thread-name).

  3. you can call pidin with argument 'threads' as suggested by others above; this will display the thread-name in the third column if one has been set up or the numeric thread ID otherwise. Alternatively, you can call pidin similar to the following in order to get both the numeric and symbolic (if available) ID-s of each thread:

    pidin -faNbh

For each thread in the system this will print the PID, process-name, TID and thread-name in that order. Refer to "use pidin" for how that works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top