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