Waiting for POSIX Signals

The POSIX environment provides a notification mechanism that is similar to events in some ways. This is the signals mechanism. For an overview of signals, refer to the POSIX User's Guide.

A POSIX application can use any of the following functions to wait for a signal to arrive: pause(), sigsuspend(), sigpause(), or sleep(). Unfortunately, these functions do not provide a method of waiting for an event and a signal at the same time. For example, if you attach an interrupt to an event, and the event is caused while the process is waiting for a signal, the interrupt is not executed until a signal is received. Even then, the signal is handled before the interrupt is executed.

If you want a process to wait for signals and other events at the same time, you must use a WAIT or WAITANDRESET statement with the INTERRUPTIBLE option. The INTERRUPTIBLE option is available only in ALGOL and NEWP.

For example, suppose a program includes the following statement:

RSLT := WAIT [INTERRUPTIBLE] ((NAPTIME), E1, E2);

This statement causes the process to wait until the first of the following events occur: a signal is received, event E1 or E2 is caused, or NAPTIME number of seconds elapses. If the WAIT statement returns because a signal is received, then RSLT stores a zero.