xref: /original-bsd/lib/libc/sys/kill.2 (revision 7afc0fa3)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)kill.2	8.3 (Berkeley) 04/19/94
7.\"
8.Dd
9.Dt KILL 2
10.Os BSD 4
11.Sh NAME
12.Nm kill
13.Nd send signal to a process
14.Sh SYNOPSIS
15.Fd #include <signal.h>
16.Ft int
17.Fn kill "pid_t pid" "int sig"
18.Sh DESCRIPTION
19The
20.Fn kill
21function sends the signal given by
22.Fa sig
23to
24.Fa pid ,
25a
26process or a group of processes.
27.Fa Sig
28may be one of the signals specified in
29.Xr sigaction 2
30or it may be 0, in which case
31error checking is performed but no
32signal is actually sent.
33This can be used to check the validity of
34.Fa pid .
35.Pp
36For a process to have permission to send a signal to a process designated
37by
38.Fa pid ,
39the real or effective user ID of the receiving process must match
40that of the sending process or the user must have appropriate privileges
41(such as given by a set-user-ID program or the user is the super-user).
42A single exception is the signal SIGCONT, which may always be sent
43to any descendant of the current process.
44.Bl -tag -width Ds
45.It \&If Fa pid No \&is greater than zero :
46.Fa Sig
47is sent to the process whose ID is equal to
48.Fa pid.
49.It \&If Fa pid No \&is zero :
50.Fa Sig
51is sent to all processes whose group ID is equal
52to the process group ID of the sender, and for which the
53process has permission;
54this is a variant of
55.Xr killpg 2 .
56.It \&If Fa pid No \&is -1 :
57If the user has super-user privileges,
58the signal is sent to all processes excluding
59system processes and the process sending the signal.
60If the user is not the super user, the signal is sent to all processes
61with the same uid as the user excluding the process sending the signal.
62No error is returned if any process could be signaled.
63.El
64.Pp
65For compatibility with System V,
66if the process number is negative but not -1,
67the signal is sent to all processes whose process group ID
68is equal to the absolute value of the process number.
69This is a variant of
70.Xr killpg 2 .
71.Sh RETURN VALUES
72Upon successful completion, a value of 0 is returned.
73Otherwise, a value of -1 is returned and
74.Va errno
75is set to indicate the error.
76.Sh ERRORS
77.Fn Kill
78will fail and no signal will be sent if:
79.Bl -tag -width [EINVAL]
80.It Bq Er EINVAL
81.Fa Sig
82is not a valid signal number.
83.It Bq Er ESRCH
84No process can be found corresponding to that specified by
85.Fa pid .
86.It Bq Er ESRCH
87The process id was given as 0
88but the sending process does not have a process group.
89.It Bq Er EPERM
90The sending process is not the super-user and its effective
91user id does not match the effective user-id of the receiving process.
92When signaling a process group, this error is returned if any members
93of the group could not be signaled.
94.El
95.Sh SEE ALSO
96.Xr getpid 2 ,
97.Xr getpgrp 2 ,
98.Xr killpg 2 ,
99.Xr sigaction 2
100.Sh STANDARDS
101The
102.Fn kill
103function is expected to
104conform to IEEE Std 1003.1-1988
105.Pq Dq Tn POSIX .
106