Sending Signals
Processes can send signals to each other using the kill()
system call, by specifying the target PID and signal number to send. Signal numbers themselves are not standardized, so programmers use preprocessor macros–such as SIGINT
, SIGSTOP
, and so on–that are defined in the signal.h
header file to refer to particular signals by their portable names. Privileged processes can send signals to any process, while unprivileged processes can send signals to another process if its UID or EUID matches the UID of the target process.
The kill()
system call can also be used to broadcast a signal to every process in a process group, by specifying the process group ID as a negative value in the PID argument to kill()
. This is used, for example, by the shell to implement job control–every command is placed in its own process group, and the shell manages the process group by sending signals to it. In addition, when the shell is running in interactive mode, with a terminal, the shell registers the foreground process group with the terminal. When the user enters a signal-generating keycode, such as ctrl-c, the terminal device sends a signal to that entire process group.