Operating Systems - Projects and Exercises

kill and raise System Functions

The left arrow above will return you to the Home page
The left arrows below will return you to the Previous page

Go back top

The kill function send a signal to a process or a group of processes. The raise function allows a process to send a signal to itself.

#include <sys/types.h>
#include <signal.h>

int kill(pid_t pid, int signo);

int raise(int signo);

Both returns: 0 if OK, -1 on error

There are four different conditions for the pid argument to kill:

pid > 0 The signal is sent to the process whose process ID is pid
pid == 0 The signal is sent to all processes whose process group ID equals the process group ID of the sender and for which the sender has permission to send the signal.
pid < 0 The signal is sent to all processes whose process group ID equals the absolute value of pid and for which the sender has permission to send the signal.
pid == -1 POSIX leaves this condition as unspecified

The list of some of the often used signals is given in the discussion of signals in the C Run Time Library and below:

#include <signal.h>
SIGABRT
abnormal termination
SIGCHLD
whenever a process terminates or stops, the SIGCHLD signal is sent to the parent.
SIGCONT
continue stopped process (NOT ANSI C, UNIX SVR4 & 4.3+BSD only)
SIGFPE
arithmetic error
SIGILL
invalid execution
SIGINT
(asynchronous) interactive attention (shell ctrl-C terminate)
SIGKILL
This signal is one of the two that can't be caught or ignored. It provides the system administrator a sure way to kill any process.
SIGSEGV
illegal storage access
SIGTERM
(asynchronous) termination request (default signal sent by kill function)
SIGTSTP
interactive stop signal - suspend the process (shell ctrl-z suspend) (NOT ANSI C, UNIX SVR4 & 4.3+BSD only)

This list is not encyclopaedic. See Stallings for a more complete list.

The descriptions of the system functions above are drawn from sources that include manuals on the Sun Solaris system and the MAC OS X Darwin/BDS system, and also from 'Advanced Programming in the UNIX Environment', W. Richard Stevens, Addison-Wesley, 1993.

Go back top

For use only by students and instructors using the supplementary material available with the text book: "Operating Systems - Internals and Design Principles", William Stallings, Prentice Hall, 5th Edition, 2004. Not to be printed out or copied by any other persons or used for any other purpose without written permission of the author(s).

©