|
|
|||||||||||||||||||
|
POSIX Signals
By Jeffrey Howard
Posix signals have a lot of associated terminology. Signals can be caught, ignored, blocked, unblocked, handled, and more. In the presence of pthreads, this variety is all the more convoluted by the addition of delivery to threads as well as processes. This document is a gentle introduction to some of the high level concepts and terminology involved. PlatformThis information is based on my understanding of posix signal and thread behavior. If you are using a non-posix compliant version of unix, the general terminology should still be helpful, but the details may be inaccurate. IntroductionA signal is a kind of notification sent from one process (or the operating system kernel) to another process. Because signals may be sent at any time, they are asynchronous. There are several terms associated with signals.
NotesThe SIGKILL and SIGSTOP signals cannot be blocked, caught, or ignored. ThreadsThe semantics of signals are not changed by using threads, as far as the outside world is concerned. Signals are still delivered to the process as a whole rather than individual threads. This should make intuitive sense. Think of the kill program used to send signals to processes. When you run the command, you give it a process ID number as a command line parameter, but you do not specify which thread in that progam should receive the signal.) Once inside the process, the signals are delivered to individual threads via the magic of pthreads. One important safety tip is that pthreads constructs like mutexes, condition variables, etc. do not have defined behavior inside signal handlers. So you cannot use pthreads calls or synchronize with other threads while inside a signal handler. Here it gets a bit complicated. Since you have threads, you can have a few different ways that signals are handled inside the process.
Another consideration is that signal actions (handlers called when the signal is caught) are global to the entire process, not particular to any one thread. Thus, while you can block a signal for just one thread, just a few threads, or all threads, you can only choose to ignore a signal for no threads or all threads. Similarly, you can choose which set of threads are not blocking a signal and may handle it, but they all use the same handler for the signal. You are controlling which threads may have to yield time to execute the handler, but you cannot control the handler they will execute on a thread by thread basis. Any thread can use sigaction() to set the handler (or SIG_DFL or SIG_IGN) for a signal. ReferencesPthreads Programming, an O'Reilly nutshell book, has about the best coverage of Pthreads, including their signal handling characteristics, that I've seen. (Or, buy from Amazon.) |
|||||||||||||||||||
|
This information is provided "as is," with no warranty or guaranty. The IAQ pages have not been maintained in some time; they're being kept up because, judging by the traffic and link-backs, people still find them useful. Copyright 1998-2004 by Jeffrey Howard and Heather Grove, except where stated otherwise. |
||||||||||||||||||||