xref: /freebsd-14.2/lib/libc/sys/kill.2 (revision b2c76c41)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)kill.2	8.3 (Berkeley) 4/19/94
29.\"
30.Dd December 1, 2019
31.Dt KILL 2
32.Os
33.Sh NAME
34.Nm kill
35.Nd send signal to a process
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.In sys/types.h
40.In signal.h
41.Ft int
42.Fn kill "pid_t pid" "int sig"
43.Sh DESCRIPTION
44The
45.Fn kill
46system call sends the signal given by
47.Fa sig
48to
49.Fa pid ,
50a
51process or a group of processes.
52The
53.Fa sig
54argument
55may be one of the signals specified in
56.Xr sigaction 2
57or it may be 0, in which case
58error checking is performed but no
59signal is actually sent.
60This can be used to check the validity of
61.Fa pid .
62.Pp
63For a process to have permission to send a signal to a process designated
64by
65.Fa pid ,
66the user must be the super-user, or
67the real or saved user ID of the receiving process must match
68the real or effective user ID of the sending process.
69A single exception is the signal SIGCONT, which may always be sent
70to any process with the same session ID as the sender.
71In addition, if the
72.Va security.bsd.conservative_signals
73.Xr sysctl 9
74is set to 1, the user is not a super-user, and
75the receiver is set-uid, then
76only job control and terminal control signals may
77be sent (in particular, only SIGKILL, SIGINT, SIGTERM, SIGALRM,
78SIGSTOP, SIGTTIN, SIGTTOU, SIGTSTP, SIGHUP, SIGUSR1, SIGUSR2).
79.Bl -tag -width Ds
80.It \&If Fa pid No \&is greater than zero :
81The
82.Fa sig
83signal
84is sent to the process whose ID is equal to
85.Fa pid .
86.It \&If Fa pid No \&is zero :
87The
88.Fa sig
89signal
90is sent to all processes whose group ID is equal
91to the process group ID of the sender, and for which the
92process has permission;
93this is a variant of
94.Xr killpg 2 .
95.It \&If Fa pid No \&is -1 :
96If the user has super-user privileges,
97the signal is sent to all processes excluding
98system processes
99(with
100.Dv P_SYSTEM
101flag set),
102process with ID 1
103(usually
104.Xr init 8 ) ,
105and the process sending the signal.
106If the user is not the super user, the signal is sent to all processes
107which the caller has permissions to, excluding the process sending the signal.
108No error is returned if any process could be signaled.
109.El
110.Pp
111If the process number is negative but not -1,
112the signal is sent to all processes whose process group ID
113is equal to the absolute value of the process number.
114This is a variant of
115.Xr killpg 2 .
116.Sh RETURN VALUES
117.Rv -std kill
118.Sh ERRORS
119The
120.Fn kill
121system call
122will fail and no signal will be sent if:
123.Bl -tag -width Er
124.It Bq Er EINVAL
125The
126.Fa sig
127argument
128is not a valid signal number.
129.It Bq Er ESRCH
130No process or process group can be found corresponding to that specified by
131.Fa pid .
132.It Bq Er EPERM
133The sending process does not have permission to send
134.Va sig
135to any receiving process.
136.El
137.Sh SEE ALSO
138.Xr getpgrp 2 ,
139.Xr getpid 2 ,
140.Xr killpg 2 ,
141.Xr sigaction 2 ,
142.Xr sigqueue 2 ,
143.Xr raise 3 ,
144.Xr init 8
145.Sh STANDARDS
146The
147.Fn kill
148system call is expected to conform to
149.St -p1003.1-90 .
150.Sh HISTORY
151A version of the
152.Fn kill
153function appeared in
154.At v3 .
155The signal number was added to the
156.Fn kill
157function in
158.At v4 .
159