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
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 existence and permission
36 checks are still performed; this can be used to check for the existence
37 of a process ID or process group ID that the caller is permitted to
38 signal.
39
40 For a process to have permission to send a signal, it must either be
41 privileged (under Linux: have the CAP_KILL capability in the user
42 namespace of the target process), or the real or effective user ID of
43 the sending process must equal the real or saved set-user-ID of the
44 target process. In the case of SIGCONT, it suffices when the sending
45 and receiving processes belong to the same session. (Historically, the
46 rules were different; see NOTES.)
47
49 On success (at least one signal was sent), zero is returned. On error,
50 -1 is returned, and errno is set appropriately.
51
53 EINVAL An invalid signal was specified.
54
55 EPERM The process does not have permission to send the signal to any
56 of the target processes.
57
58 ESRCH The process or process group does not exist. Note that an
59 existing process might be a zombie, a process that has termi‐
60 nated execution, but has not yet been wait(2)ed for.
61
63 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
64
66 The only signals that can be sent to process ID 1, the init process,
67 are those for which init has explicitly installed signal handlers.
68 This is done to assure the system is not brought down accidentally.
69
70 POSIX.1 requires that kill(-1,sig) send sig to all processes that the
71 calling process may send signals to, except possibly for some implemen‐
72 tation-defined system processes. Linux allows a process to signal
73 itself, but on Linux the call kill(-1,sig) does not signal the calling
74 process.
75
76 POSIX.1 requires that if a process sends a signal to itself, and the
77 sending thread does not have the signal blocked, and no other thread
78 has it unblocked or is waiting for it in sigwait(3), at least one
79 unblocked signal must be delivered to the sending thread before the
80 kill() returns.
81
82 Linux notes
83 Across different kernel versions, Linux has enforced different rules
84 for the permissions required for an unprivileged process to send a sig‐
85 nal to another process. In kernels 1.0 to 1.2.2, a signal could be
86 sent if the effective user ID of the sender matched effective user ID
87 of the target, or the real user ID of the sender matched the real user
88 ID of the target. From kernel 1.2.3 until 1.3.77, a signal could be
89 sent if the effective user ID of the sender matched either the real or
90 effective user ID of the target. The current rules, which conform to
91 POSIX.1, were adopted in kernel 1.3.78.
92
94 In 2.6 kernels up to and including 2.6.7, there was a bug that meant
95 that when sending signals to a process group, kill() failed with the
96 error EPERM if the caller did not have permission to send the signal to
97 any (rather than all) of the members of the process group. Notwith‐
98 standing this error return, the signal was still delivered to all of
99 the processes for which the caller had permission to signal.
100
102 kill(1), _exit(2), signal(2), tkill(2), exit(3), killpg(3),
103 sigqueue(3), capabilities(7), credentials(7), signal(7)
104
106 This page is part of release 5.02 of the Linux man-pages project. A
107 description of the project, information about reporting bugs, and the
108 latest version of this page, can be found at
109 https://www.kernel.org/doc/man-pages/.
110
111
112
113Linux 2017-09-15 KILL(2)