1KILL(2) Linux Programmer's Manual KILL(2)
2
3
4
6 kill - send signal to a process
7
9 #include <sys/types.h>
10 #include <signal.h>
11
12 int kill(pid_t pid, int sig);
13
14 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16 kill(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
17
19 The kill() system call can be used to send any signal to any process
20 group or process.
21
22 If pid is positive, then signal sig is sent to the process with the ID
23 specified by pid.
24
25 If pid equals 0, then sig is sent to every process in the process group
26 of the calling process.
27
28 If pid equals -1, then sig is sent to every process for which the call‐
29 ing process has permission to send signals, except for process 1
30 (init), but see below.
31
32 If pid is less than -1, then sig is sent to every process in the
33 process group whose ID is -pid.
34
35 If sig is 0, then no signal is sent, but error checking is still per‐
36 formed; this can be used to check for the existence of a process ID or
37 process group ID.
38
39 For a process to have permission to send a signal it must either be
40 privileged (under Linux: have the CAP_KILL capability), or the real or
41 effective user ID of the sending process must equal the real or saved
42 set-user-ID of the target process. In the case of SIGCONT it suffices
43 when the sending and receiving processes belong to the same session.
44
46 On success (at least one signal was sent), zero is returned. On error,
47 -1 is returned, and errno is set appropriately.
48
50 EINVAL An invalid signal was specified.
51
52 EPERM The process does not have permission to send the signal to any
53 of the target processes.
54
55 ESRCH The pid or process group does not exist. Note that an existing
56 process might be a zombie, a process which already committed
57 termination, but has not yet been wait(2)ed for.
58
60 SVr4, 4.3BSD, POSIX.1-2001.
61
63 The only signals that can be sent to process ID 1, the init process,
64 are those for which init has explicitly installed signal handlers.
65 This is done to assure the system is not brought down accidentally.
66
67 POSIX.1-2001 requires that kill(-1,sig) send sig to all processes that
68 the calling process may send signals to, except possibly for some
69 implementation-defined system processes. Linux allows a process to
70 signal itself, but on Linux the call kill(-1,sig) does not signal the
71 calling process.
72
73 POSIX.1-2001 requires that if a process sends a signal to itself, and
74 the sending thread does not have the signal blocked, and no other
75 thread has it unblocked or is waiting for it in sigwait(3), at least
76 one unblocked signal must be delivered to the sending thread before the
77 kill() returns.
78
79 Linux notes
80 Across different kernel versions, Linux has enforced different rules
81 for the permissions required for an unprivileged process to send a sig‐
82 nal to another process. In kernels 1.0 to 1.2.2, a signal could be
83 sent if the effective user ID of the sender matched that of the
84 receiver, or the real user ID of the sender matched that of the
85 receiver. From kernel 1.2.3 until 1.3.77, a signal could be sent if
86 the effective user ID of the sender matched either the real or effec‐
87 tive user ID of the receiver. The current rules, which conform to
88 POSIX.1-2001, were adopted in kernel 1.3.78.
89
91 In 2.6 kernels up to and including 2.6.7, there was a bug that meant
92 that when sending signals to a process group, kill() failed with the
93 error EPERM if the caller did not have permission to send the signal to
94 any (rather than all) of the members of the process group. Notwith‐
95 standing this error return, the signal was still delivered to all of
96 the processes for which the caller had permission to signal.
97
99 _exit(2), killpg(2), signal(2), tkill(2), exit(3), sigqueue(3), capa‐
100 bilities(7), credentials(7), signal(7)
101
103 This page is part of release 3.53 of the Linux man-pages project. A
104 description of the project, and information about reporting bugs, can
105 be found at http://www.kernel.org/doc/man-pages/.
106
107
108
109Linux 2013-02-05 KILL(2)