Node:Signaling Another Process, Next:Permission for kill, Previous:Signaling Yourself, Up:Generating Signals
The kill
function can be used to send a signal to another process.
In spite of its name, it can be used for a lot of things other than
causing a process to terminate. Some examples of situations where you
might want to send signals between processes are:
This section assumes that you know a little bit about how processes work. For more information on this subject, see Processes.
The kill
function is declared in signal.h
.
int kill (pid_t pid, int signum) | Function |
The kill function sends the signal signum to the process
or process group specified by pid. Besides the signals listed in
Standard Signals, signum can also have a value of zero to
check the validity of the pid.
The pid specifies the process or process group to receive the signal:
A process can send a signal to itself with a call like The return value from The following
|
int killpg (int pgid, int signum) | Function |
This is similar to kill , but sends signal signum to the
process group pgid. This function is provided for compatibility
with BSD; using kill to do this is more portable.
|
As a simple example of kill
, the call kill (getpid (), sig)
has the same effect as raise (sig)
.