CS 321 Spring 2013  >  Lecture Notes for Friday, February 15, 2013

CS 321 Spring 2013
Lecture Notes for Friday, February 15, 2013

Message-Passing IPC (cont’d)

POSIX Signals

Simple message-passing mechanism. A traditional part of C library under *ix OSs. Very little information is sent—only the signal itself. By default, asynchronous, handler function executed using standard process stack.

Must include <signal.h>. A handler function takes an int (the signal) and returns void. Set up a handler by calling system call signal, passing the signal name and a pointer to the handler function.

Signals are sent by kill system call. Also a program named kill can be used on the command line.

Here are some of the more common signals. There are many others, most of which are rarely used. The default response is what happens to the process receiving the signal if it has not set up a handler function.

Signal Traditionally Sent By Can Be Handled Default Response
SIGINT Ctrl-C Yes Terminate
SIGKILL   No Terminate
SIGSTOP Ctrl-Z No Suspend
SIGCONT Shell bg command [also fg] No Wake if suspended; otherwise ignore
SIGALRM System call alarm(time_in_secs) Yes Terminate

See sig1.cpp for a program that sets up a signal handler.

The alarm signal (SIGALRM) is most often used by a process to signal itself. The signal is sent after some fixed amount of time has elapsed.

See sig2.cpp for a program that uses SIGALRM.


CS 321 Spring 2013: Lecture Notes for Friday, February 15, 2013 / Updated: 15 Feb 2013 / Glenn G. Chappell / ggchappell@alaska.edu