KILL(3B) KILL(3B)
kill - send signal to a process (4.3BSD)
#include <signal.h>
int kill(pid_t pid, int sig);
To use any of the BSD signal routines (kill(3B), killpg(3B),
sigblock(3B), signal(3B), sigpause(3B), sigsetmask(3B), sigstack(2B),
sigvec(3B)) you must either
1) #define _BSD_SIGNALS or _BSD_COMPAT before including <signal.h>, or
2) specify one of them in the compile command or makefile:
cc -D_BSD_SIGNALS -o prog prog.c
kill sends the signal sig to a process, specified by the process number
pid. Sig may be one of the signals specified in sigvec(3B), 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 sending and receiving processes must have the same effective user ID,
otherwise this call is restricted to the super-user. A single exception
is the signal SIGCONT, which may always be sent to any descendant of the
current process.
If the process number is 0, the signal is sent to all processes in the
sender's process group; this is a variant of killpg(3B).
If the process number is -1 and the user is the super-user, the signal is
broadcast universally except to system processes. If the process number
is -1 and the user is not the super-user, the signal is broadcast
universally to all processes with the same uid as the user. No error is
returned if any process could be signaled.
For compatibility with System V, if the process number is negative but
not -1, the signal is sent to all processes whose process group ID is
equal to the absolute value of the process number. This is a variant of
killpg(3B).
Processes may send signals to themselves.
Upon successful completion, a value of 0 is returned. Otherwise, a value
of -1 is returned and errno is set to indicate the error.
Page 1
KILL(3B) KILL(3B)
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.
[ESRCH] The process id was given as 0 but the sending process does
not have a process group.
[EPERM] The sending process is not the super-user and its
effective user ID does not match the effective user ID of
the receiving process.
getpid(2), getpgrp(2), killpg(3B), sigvec(3B)
CAVEATS (IRIX)
When the process number is -1, the process sending the signal is NOT
included in the delivery group. In the IRIX implementation, the sending
process receives the signal, too.
4.3BSD's implementation of kill returns EPERM if any members of a process
group can not be signaled (when kill is invoked with a pid of 0). The
IRIX implementation does not.
WARNING (IRIX)
The 4.3BSD and System V signal facilities have different semantics.
Using both facilities in the same program is strongly discouraged and
will result in unpredictable behavior.
PPPPaaaaggggeeee 2222 [ Back ]
|