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