Welcome to the Linux Foundation Forum!

Sending a signal to a pthread with sigqueue


Dear Linux experts,

Is it possible to send a signal to a pthread with sigqueue() ?

The argument of the function is a process ID and not a thread ID.

I can use pthread_kill() but I need to send an accompanying value as in sigqueue().




  • woboyle
    woboyle Posts: 501
    This is not an insurmountable problem, using pthread_kill() to signal a thread with data. AFAIK, using sigqueue() is not thread safe. It should only be handled in the main thread of the program. However, you can create an associative array of structures that associate a thread id with the data you wish to communicate. Then, the thread's signal handler can look at the associated with its tid and act accordingly. FWIW, you could try to use the thread id in place of a process id for sigqueue(). I don't know if that would work, and it might in some systems, but not in others. Caveat programmer! :-)
  • hwatari
    Hi woboyle,
    Thank you very much for your reply.
    On Ubuntu linux, sigqueue with thread id does not work.
    My intention was to have 4 slave threads send the same signal to the master thread asyncronously so accessing the master's associtive structure by the slaves must be carried out with a mutex.
    So for lack of simpler solutions, I will have 4 slaves send 4 different signals because only information I need to send with the signal is from which slave the signal is originating.


Upcoming Training