1kill(2)                       System Calls Manual                      kill(2)
2
3
4

NAME

6       kill - send signal to a process
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <signal.h>
13
14       int kill(pid_t pid, int sig);
15
16   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18       kill():
19           _POSIX_C_SOURCE
20

DESCRIPTION

22       The  kill()  system  call can be used to send any signal to any process
23       group or process.
24
25       If pid is positive, then signal sig is sent to the process with the  ID
26       specified by pid.
27
28       If pid equals 0, then sig is sent to every process in the process group
29       of the calling process.
30
31       If pid equals -1, then sig is sent to every process for which the call‐
32       ing  process  has  permission  to  send  signals,  except for process 1
33       (init), but see below.
34
35       If pid is less than -1, then sig  is  sent  to  every  process  in  the
36       process group whose ID is -pid.
37
38       If  sig  is  0,  then  no  signal is sent, but existence and permission
39       checks are still performed; this can be used to check for the existence
40       of  a  process  ID  or process group ID that the caller is permitted to
41       signal.
42
43       For a process to have permission to send a signal, it  must  either  be
44       privileged (under Linux: have the CAP_KILL capability in the user name‐
45       space of the target process), or the real or effective user ID  of  the
46       sending  process must equal the real or saved set-user-ID of the target
47       process.  In the case of SIGCONT, it suffices when the sending and  re‐
48       ceiving processes belong to the same session.  (Historically, the rules
49       were different; see NOTES.)
50

RETURN VALUE

52       On success (at least one signal was sent), zero is returned.  On error,
53       -1 is returned, and errno is set to indicate the error.
54

ERRORS

56       EINVAL An invalid signal was specified.
57
58       EPERM  The  calling process does not have permission to send the signal
59              to any of the target processes.
60
61       ESRCH  The target process or process group does not exist.   Note  that
62              an existing process might be a zombie, a process that has termi‐
63              nated execution, but has not yet been wait(2)ed for.
64

STANDARDS

66       POSIX.1-2008.
67

HISTORY

69       POSIX.1-2001, SVr4, 4.3BSD.
70
71   Linux notes
72       Across different kernel versions, Linux has  enforced  different  rules
73       for the permissions required for an unprivileged process to send a sig‐
74       nal to another process.  In Linux 1.0 to 1.2.2, a signal could be  sent
75       if the effective user ID of the sender matched effective user ID of the
76       target, or the real user ID of the sender matched the real user  ID  of
77       the  target.   From Linux 1.2.3 until 1.3.77, a signal could be sent if
78       the effective user ID of the sender matched either the real  or  effec‐
79       tive  user  ID  of  the  target.   The  current rules, which conform to
80       POSIX.1, were adopted in Linux 1.3.78.
81

NOTES

83       The only signals that can be sent to process ID 1,  the  init  process,
84       are  those  for  which  init  has explicitly installed signal handlers.
85       This is done to assure the system is not brought down accidentally.
86
87       POSIX.1 requires that kill(-1,sig) send sig to all processes  that  the
88       calling process may send signals to, except possibly for some implemen‐
89       tation-defined system processes.  Linux allows a process to signal  it‐
90       self,  but  on  Linux the call kill(-1,sig) does not signal the calling
91       process.
92
93       POSIX.1 requires that if a process sends a signal to  itself,  and  the
94       sending  thread  does  not have the signal blocked, and no other thread
95       has it unblocked or is waiting for it in sigwait(3), at least  one  un‐
96       blocked  signal  must  be  delivered  to  the sending thread before the
97       kill() returns.
98

BUGS

100       In Linux 2.6 up to and including Linux 2.6.7,  there  was  a  bug  that
101       meant  that when sending signals to a process group, kill() failed with
102       the error EPERM if the caller did not have permission to send the  sig‐
103       nal to any (rather than all) of the members of the process group.  Not‐
104       withstanding this error return, the signal was still delivered  to  all
105       of the processes for which the caller had permission to signal.
106

SEE ALSO

108       kill(1),  _exit(2), pidfd_send_signal(2), signal(2), tkill(2), exit(3),
109       killpg(3), sigqueue(3), capabilities(7), credentials(7), signal(7)
110
111
112
113Linux man-pages 6.04              2023-03-30                           kill(2)
Impressum