next up previous contents
Next: 10.2.1 Signals under SVR4 Up: 10 Porting Applications to Previous: 10.1 Introduction

10.2 Signal handling

Over the years, the definition and semantics of signals have been modified in various ways by different implementations of UNIX. Today, there are two major classes of symbols: unreliable and reliable. Unreliable signals are those for which the signal handler does not remain installed once called. These ``one-shot'' signals must re-install the signal handler within the signal handler itself, if the program wishes the signal to remain installed. Because of this, there is a race condition in which the signal can arrive again before the handler is re-installed, which can cause the signal to either be lost or for the original behavior of the signal to be triggered (such as killing the process). Therefore, these signals are ``unreliable'' because the signal catching and handler re-installation operations are nonatomic.

Under unreliable signal semantics, system calls are not restarted automatically when interrupted by a signal. Therefore, in order for a program to account for all cases, the program would need to check the value of errno after every system call, and reissue the system call if its value is EINTR.

Along similar lines, unreliable signal semantics don't provide an easy way to get an atomic pause operation (put the process to sleep until a signal arrives). Because of the unreliable nature of reinstalling signal handlers, there are cases in which a signal can arrive without the program realizing this.

Under reliable signal semantics, on the other hand, the signal handler remains installed when called, and the race condition for reinstallation is avoided. Also, certain system calls can be restarted, and an atomic pause operation is available via the POSIX sigsuspend function.

Converted on:
Fri Mar 29 14:43:04 EST 1996