KILL(2V) — SYSTEM CALLS
NAME
kill − send a signal to a process or a group of processes
SYNOPSIS
kill(pid, sig)
int pid, sig;
DESCRIPTION
kill() sends the signal sig to a process or a group of processes. The process or group of processes to which the signal is to be sent is specified by pid. sig may be one of the signals specified in sigvec(2), or it may be 0, in which case error checking is performed but no signal is actually sent. This can be used to check the validity of pid.
The real or effective user ID of the sending process must match the real or saved set-user ID of the receiving process, unless the effective user ID of the sending process is super-user. A single exception is the signal SIGCONT, which may always be sent to any descendant of the current process.
In the following discussion, “system processes” are processes, such as processes 0 and 2, that are not running a regular user program.
If pid is greater than zero, the signal is sent to the process whose process ID is equal to pid. pid may equal 1.
If pid is 0, the signal is sent to all processes, except system processes and process 1, whose process group ID is equal to the process group ID of the sender; this is a variant of killpg(2).
If pid is −1 and the effective user ID of the sender is not super-user, the signal is sent to all processes, except system processes, process 1, and the process sending the signal, whose real or saved set-user ID matches the real or effective ID of the sender.
If pid is −1 and the effective user ID of the sender is super-user, the signal is sent to all processes except system processes, process 1, and the process sending the signal.
If pid is negative but not −1, the signal is sent to all processes, except system processes, process 1, and the process sending the signal, whose process group ID is equal to the absolute value of pid; this is a variant of killpg(2).
Processes may send signals to themselves.
SYSTEM V DESCRIPTION
If a signal is sent to a group of processes (as with, if pid is 0 or negative), and if the process sending the signal is a member of that group, the signal is sent to that process as well.
The signal SIGKILL cannot be sent to process 1.
RETURN VALUE
Upon successful completion, a value of 0 is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
ERRORS
kill() will fail and no signal will be sent if any of the following occur:
EINVAL sig is not a valid signal number.
ESRCH No process can be found corresponding to that specified by pid.
EPERM The effective user ID of the sending process is not super-user, and neither its real nor effective user ID matches the real or saved set-user ID of the receiving process.
SYSTEM V ERRORS
kill() will also fail, and no signal will be sent, if the following occurs:
EINVAL sig is SIGKILL and pid is 1.
SEE ALSO
getpid(2), killpg(2), setpgrp(2V), sigvec(2)
Sun Release 4.0 — Last change: 22 March 1989