Chapter 14. Signals

   

Signals are the software equivalent of a hardware trap or interrupt. They are a way of informing a process or thread that an event has occurred. Just like their hardware counterparts, signals can be caused either by the instruction being executed or by an external event.

A signal that is caused by the current instruction is a synchronous signal. Examples are floating-point exceptions and memory faults. Another way to think of a synchronous signal is as a signal that a thread causes to be sent to itself.

A signal that is caused by an eternal event is an asynchronous signal. These are signals that originate outside the current thread for example, a signal due to data being ready from a terminal, or another thread using the kill() system call to send a signal.

Another aspect of synchronous versus asynchronous signals has to do with multithreaded processes. Since a synchronous signal is caused by a thread, it also delivered to that thread to be handled. An asynchronous signal can be delivered to any thread within the process.

Being synchronous or asynchronous is a property of how the signal is delivered not the type of signal. The SIGSEGV signal is normally caused by a bad memory access and so is normally sent synchronously but it could also be sent asynchronously. A process could use the kill() system call to send a SIGSEGV signal.

In general, a process can choose to ignore a signal, hold the signal pending, or handle it by calling a signal-handling routine. For each signal type, there is also a default action, and a process can request the default treatment. This default is different for different signals. The scenario gets a bit more complicated when a process is multithreaded. In addition to the above, the application can specify which thread will handle a signal. In this way one or more threads can be used specifically as signal handlers while other threads are allowed to run without interruption.

Let's take a look at how signals are processed from setting up a signal handler to signal generation, delivery, and handling.



HP-UX 11i Internals
HP-UX 11i Internals
ISBN: 0130328618
EAN: 2147483647
Year: 2006
Pages: 167

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net