kill(2) kill(2)
NAME
kill - send a signal to a process or a group of processes
SYNOPSIS
#include <sys/types.h>
#include <signal.h>
int kill(pid_t pid, int sig);
DESCRIPTION
kill sends a signal 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. The signal that is to be sent is
specified by sig and is either one from the list given in
signal [see signal(5)], or 0. If sig is 0 (the null signal),
error checking is performed but no signal is actually sent.
This can be used to check the validity of pid.
In order to send the signal to the target process (pid), the
sending process must have permission to do so, subject to the
following ownership restrictions:
The real or effective user ID of the sending process
must match the real or saved [from exec] user ID of the
receiving process, unless the sending process has the
P_OWNER privilege, or sig is SIGCONT and the sending
process has the same session ID as the receiving
process.
The process with ID 0 and the process with ID 1 are special
processes [see intro(2)] and will be referred to below as
proc0 and proc1, respectively.
If pid is greater than 0, sig will be sent to the process
whose process ID is equal to pid, subject to the ownership
restrictions, above. pid may equal 1.
If pid is negative but not (pid_t)-1, sig will be sent to all
processes whose process group ID is equal to the absolute
value of pid and for which the process has permission to send
a signal.
If pid is 0, sig will be sent to all processes excluding proc0
and proc1 whose process group ID is equal to the process group
ID of the sender. Permission is needed to send a signal to
process groups.
Copyright 1994 Novell, Inc. Page 1
kill(2) kill(2)
If pid is (pid_t)-1 and the sending process does not have the
P_OWNER privilege, sig will be sent to all processes excluding
proc0 and proc1 whose real user ID is equal to the effective
user ID of the sender.
If pid is (pid_t)-1 and the sending process has the P_OWNER
privilege, sig will be sent to all processes excluding proc0
and proc1.
Return Values
On success, kill returns 0. On failure, kill returns -1, sets
errno to identify the error, and sends no signal.
Errors
In the following conditions, kill fails and sets errno to:
EINVAL sig is not a valid signal number.
EPERM sig is SIGKILL and pid is (pid_t)1 (i.e., pid
specifies proc1).
EPERM The sending process does not have the P_OWNER
privilege, the real or effective user ID of the
sending process does not match the real or
saved user ID of the receiving process, and the
calling process is not sending SIGCONT to a
process that shares the same session ID.
ESRCH No process or process group can be found
corresponding to that specified by pid.
REFERENCES
getpid(2), getsid(2), intro(2), kill(1), setpgrp(2),
sigaction(2), signal(2), sigsend(2)
NOTICES
sigsend is a more versatile way to send signals to processes.
The user is encouraged to use sigsend instead of kill.
Considerations for Threads Programming
Signals can be posted from one process to another via kill but
not to specific threads within the receiving process. See
signal(5) for further details. See thr_kill(3thread) for
intra-process, thread-to-thread signaling.
Copyright 1994 Novell, Inc. Page 2
kill(2) kill(2)
Considerations for Lightweight Processes
Additionally, signals from one process cannot be addressed to
specific LWPs in the receiving process.
Copyright 1994 Novell, Inc. Page 3