LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   do threads in the process share the signal handler? (https://www.linuxquestions.org/questions/linux-software-2/do-threads-in-the-process-share-the-signal-handler-827478/)

feiyinzilgd 08-20-2010 11:25 AM

do threads in the process share the signal handler?
 
Hi
I am studying the Advanced Programming in the Unix Environment these days. When I come to the chapter of Threads and signals, I find it difficult for me to understand the statement that the signal disposition is shared by all threads in the process.

Dose it mean that threads in the same process share the signal handler or just the attributes that set by sigaction ?



I will appreciate your helping me.

chrism01 08-21-2010 08:10 PM

It's true that signals are sent to the (overall) process (pid); you can't send a signal to an individual thrd, so you need to be real careful and ideally minimize the amt of code in a sig handler routine.
Best to just set a flag for the normal code to deal with and leave it at that.
One exception I've used is to use SIGHUP to re-read the cfg file. Apache does the same.

Also, you might want to ask the mods to move this to the Programming forum (use the Report button)

feiyinzilgd 08-22-2010 07:57 AM

Quote:

Originally Posted by chrism01 (Post 4073702)
It's true that signals are sent to the (overall) process (pid); you can't send a signal to an individual thrd, so you need to be real careful and ideally minimize the amt of code in a sig handler routine.
Best to just set a flag for the normal code to deal with and leave it at that.
One exception I've used is to use SIGHUP to re-read the cfg file. Apache does the same.

Also, you might want to ask the mods to move this to the Programming forum (use the Report button)

Thank for you reply.

From my understanding, If a nonblocking signal is sent to a process,every thread in the processs will do the same thing.Because the threads share the the signal handler.

Is that right?


I new here.This my first post in this forum.I do not know how to move my post to programming.

fpmurphy 08-22-2010 12:06 PM

Quote:

Originally Posted by chrism01 View Post
It's true that signals are sent to the (overall) process (pid); you can't send a signal to an individual thrd
Humm. You can send a signal to an individual thread. The POSIX API is pthread_kill

jiml8 08-22-2010 12:13 PM

Quote:

Originally Posted by feiyinzilgd (Post 4074049)
Thank for you reply.

From my understanding, If a nonblocking signal is sent to a process,every thread in the processs will do the same thing.Because the threads share the the signal handler.

Is that right?


I new here.This my first post in this forum.I do not know how to move my post to programming.

The threads will do what they are told to do. The signal handler will dictate what the threads are told to do.

chrism01 08-23-2010 04:15 AM

@fmurphy: indeed, but from that same page:
Quote:

Note that pthread_kill() only causes the signal to be handled in the context of the given thread; the signal action (termination or stopping) affects the process as a whole.
What I meant to say was that a signal sent from outside the process eg

kill -SIGHUP <pid of process>

cannot be specified to target a given thread; it's delivered to the process as a whole and the actual thread that will first respond is undefined.


All times are GMT -5. The time now is 07:13 PM.