-   Programming (
-   -   !!! about signals !!! (

b2na 01-03-2005 04:14 PM

!!! about signals !!!
[C/C++ application, Linux, signal, thread, process]

I have an application, one single process and multiple threads. Every thread has its run function. When a signal is send to the process, all threads are interrupted? And if the signal is handled, what happens next? I supose the signal is handled and then all the operations are... restarted... I'm not sure about that... can someone explain a little bit to me what happens to the running operations when a signal arrives and it's handled?

Thank you.

michael_util 01-04-2005 06:24 PM


I am not a developer by any means ... but I believe this is entierly depends on how you write your application.

For example in order to use signals with bash scritps you need to have a trap setup for them. If I setup a trap for signal 10 (trap cmd_func 10) when I sent a signal 10 to the process it will run that function cmd_func. If I do not have a trap setup then nothing happens.


btmiller 01-05-2005 12:22 AM

Read the man page for pthread_sigmask -- it has some info on this. POSIX specifies that a signal is only delivered to one thread, but there are a few quirks in the Linux implementation of this. Read that man page for all the gory details. There is a way (pthread_kill) to send signals between threads.

If a signal has handled, the program will continue to execurte where it left off once the signal handler has finished. The exceptions are if the handler terminates the program or jumps (e.g. via siglongjmp) somewhere else.

b2na 01-05-2005 05:15 AM

I see... Thanks for the clarification with siglongjmp... I had some problems with that too.... But there are signals sent to _the process_ and signals sent to thread with pthread_kill. In my application I have a signal sent to the process and in that process I have multiple threads. So, the signal sent to the process wil stop and restart then the threads, all the threads? (the signal is sent to one process and in that process I'm running multiple threads)

chrism01 02-04-2005 01:34 AM

As I understnd it, in your case (sig sent to process), the answer is to assume any thread will catch it, so make the sig handler avail/in all threads and set a global or something that the other threads can take notice of...
A lot of systems have a master thread that actually does something about the sig when it sees the global var is set.

All times are GMT -5. The time now is 07:52 AM.