1.\" $OpenBSD: kill.2,v 1.17 2007/05/31 19:19:32 jmc 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: May 31 2007 $ 34.Dt KILL 2 35.Os 36.Sh NAME 37.Nm kill 38.Nd send signal to a process 39.Sh SYNOPSIS 40.Fd #include <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.El 91.Pp 92Setuid and setgid processes are dealt with slightly differently. 93For the non-root user, to prevent attacks against such processes, some signal 94deliveries are not permitted and return the error 95.Er EPERM . 96The following signals are allowed through to this class of processes: 97.Dv SIGKILL , 98.Dv SIGINT , 99.Dv SIGTERM , 100.Dv SIGSTOP , 101.Dv SIGTTIN , 102.Dv SIGTTOU , 103.Dv SIGTSTP , 104.Dv SIGHUP , 105.Dv SIGUSR1 , 106.Dv SIGUSR2 . 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 3 . 114.Sh RETURN VALUES 115Upon successful completion, a value of 0 is returned. 116Otherwise, a value of \-1 is returned and 117.Va errno 118is set to indicate the error. 119.Sh ERRORS 120.Fn kill 121will fail and no signal will be sent if: 122.Bl -tag -width Er 123.It Bq Er EINVAL 124.Fa sig 125is not a valid signal number. 126.It Bq Er ESRCH 127No process can be found corresponding to that specified by 128.Fa pid . 129.It Bq Er ESRCH 130The process ID was given as 0 131but the sending process does not have a process group. 132.It Bq Er EPERM 133The sending process is not the superuser and its effective 134user ID does not match the effective user ID of the receiving process. 135When signaling a process group, this error is returned if any members 136of the group could not be signaled. 137.El 138.Sh SEE ALSO 139.Xr getpgrp 2 , 140.Xr getpid 2 , 141.Xr sigaction 2 , 142.Xr killpg 3 , 143.Xr raise 3 144.Sh STANDARDS 145The 146.Fn kill 147function is expected to conform to 148.St -p1003.1-88 . 149