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