xref: /netbsd/lib/libc/sys/kill.2 (revision 6550d01e)
1.\"	$NetBSD: kill.2,v 1.21 2008/07/13 15:16:26 dholland Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)kill.2	8.3 (Berkeley) 4/19/94
31.\"
32.Dd April 19, 1994
33.Dt KILL 2
34.Os
35.Sh NAME
36.Nm kill
37.Nd send signal to a process
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In signal.h
42.Ft int
43.Fn kill "pid_t pid" "int sig"
44.Sh DESCRIPTION
45The
46.Fn kill
47function sends the signal given by
48.Fa sig
49to
50.Fa pid ,
51a
52process or a group of processes.
53.Fa sig
54may be one of the signals specified in
55.Xr sigaction 2
56or it may be 0, in which case
57error checking is performed but no
58signal is actually sent.
59This can be used to check the validity of
60.Fa pid .
61.Pp
62For a process to have permission to send a signal to a process designated
63by
64.Fa pid ,
65the real or effective user ID of the receiving process must match
66that of the sending process or the user must have appropriate privileges
67(such as given by a set-user-ID program or the user is the super-user).
68A single exception is the signal SIGCONT, which may always be sent
69to any descendant of the current process.
70.Bl -tag -width Ds
71.It \&If Fa pid No \&is greater than zero :
72.Fa sig
73is sent to the process whose ID is equal to
74.Fa pid .
75.It \&If Fa pid No \&is zero :
76.Fa sig
77is sent to all processes whose process group ID is equal
78to the process group ID of the sender, and for which the
79process has permission;
80this is a variant of
81.Xr killpg 3 .
82.It \&If Fa pid No \&is \-1 :
83If the user has super-user privileges,
84the signal is sent to all processes excluding
85system processes and the process sending the signal.
86If the user is not the super user, the signal is sent to all processes
87with the same uid as the user excluding the process sending the signal.
88No error is returned if any process could be signaled.
89.El
90.Pp
91For compatibility with System V,
92if the process number is negative but not \-1,
93the signal is sent to all processes whose process group ID
94is equal to the absolute value of the process number.
95This is a variant of
96.Xr killpg 3 .
97.Sh RETURN VALUES
98Upon successful completion, a value of 0 is returned.
99Otherwise, a value of \-1 is returned and
100.Va errno
101is set to indicate the error.
102.Sh ERRORS
103.Fn kill
104will fail and no signal will be sent if:
105.Bl -tag -width Er
106.It Bq Er EINVAL
107.Fa sig
108is not a valid signal number.
109.It Bq Er ESRCH
110No process can be found corresponding to that specified by
111.Fa pid .
112.It Bq Er ESRCH
113The process id was given as 0
114but the sending process does not have a process group.
115.It Bq Er EPERM
116The sending process is not the super-user and its effective
117user id does not match the effective user-id of the receiving process.
118When signaling a process group, this error is returned if any members
119of the group could not be signaled.
120.El
121.Sh SEE ALSO
122.Xr getpgrp 2 ,
123.Xr getpid 2 ,
124.Xr sigaction 2 ,
125.Xr killpg 3 ,
126.Xr signal 7
127.Sh STANDARDS
128The
129.Fn kill
130function is expected to conform to
131.St -p1003.1-90 .
132