Unit4 Signals
Unit4 Signals
Signal Handling
syllabus
• Signal concepts
• signal function
• unreliable signals
• interrupted system calls
• reentrant functions
• SIGCLD semantics
• reliable-signal technology
• kill and raise
• alarm and pause
• signal sets
• Sigprocmask
• Sigpending
• sigsetjmp and siglongjmp
• sigsuspend, abort, system function revisited, sleep (TextBook-2: Topics: 10.2- 10.13, 10.15-
10.19)
Signals
• Signals are software interrupts.
• Most nontrivial application programs need to deal with signals.
• Signals provide a way of handling asynchronous events—
• for example, a user at a terminal typing the interrupt key to stop a
program or the next program in a pipeline terminating prematurely.
• BSD and SVR3 made changes to the signal model, adding what are
called reliable signals
• POSIX.1 standardized the reliable-signal routines
signals
• every signal has a name.
• begin with the three characters SIG.
• For example, SIGABRT is the abort signal that is generated when a process calls the
abort function.
• SIGALRM is the alarm signal that is generated when the timer set by the alarm
function goes off.
• Version 7 had 15 different signals; SVR4 and 4.4BSD both had 31 different signals.
FreeBSD 8.0 supports 32 different signals.
• Linux 3.2.0 each support 31 different signals, whereas Solaris 10 supports 40 different
signals.
• Signal names are all defined by positive integer constants (the signal number) in the
header .
signals
• No signal has a signal number of 0.
• The terminal-generated signals.
• Hardware exceptions –ex SIGSEGV -invalid memory reference.
• The kill(2) function allows a process to send any signal to another process or process group. there
are limitations: we have to be the owner of the process that we’re sending the signal to, or we
have to be the superuser
• The kill(1) command allows us to send signals to other processes. This program is just an interface
to the kill function. This command is often used to terminate a runaway background process.
• Software conditions can generate signals when a process should be notified of various events.
These aren’t hardware-generated conditions (as is the divideby-0 condition), but software
conditions. Examples are SIGURG (generated when out-of-band data arrives over a network
connection), SIGPIPE (generated when a process writes to a pipe that has no reader), and
SIGALRM (generated when an alarm clock set by the process expires).
signals
• We can tell the kernel to do one of three things when a signal occurs.
• the action associated with a signal.
1. Ignore the signal.
• but two signals can never be ignored: SIGKILL and SIGSTOP.
• Also, if we ignore some of the signals that are generated by a hardware exception (such as illegal
memory reference or divide by 0), the behavior of the process is undefined. \
2. Catch the signal. If the SIGCHLD signal is caught, it means that a child process has terminated, so
the signal-catching function can call waitpid to fetch the child’s process ID and termination status.
SIGTERM signal (the termination signal that is the default signal sent by the kill command) to clean
up the temporary files. Note that the two signals SIGKILL and SIGSTOP can’t be caught
3. the default action apply
When the default action is labeled ‘‘terminate+core,’’ it means that a memory image of the process
is left in the file named core of the current working directory of the process.
This file can be used with most UNIX System debuggers to examine the state of the process at the
time it terminated. (fig 10.1)
signals