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