kill(2)


kill -- send a signal to a process or a group of processes

Synopsis

   #include <sys/types.h>
   #include <signal.h>
   

int kill(pid_t pid, int sig);

Description

kill sends a signal to a process or a group of processes. The process or group of processes to which the signal is to be sent is specified by pid. The signal that is to be sent is specified by sig and is either one from the list given in signal [see signal(5)], or 0. If sig is 0 (the null signal), error checking is performed but no signal is actually sent. This can be used to check the validity of pid.

In order to send the signal to the target process (pid), the sending process must have permission to do so, subject to the following ownership restrictions:

The process with ID 0 and the process with ID 1 are special processes [see intro(2)] and will be referred to below as proc0 and proc1, respectively.

If pid is greater than 0, sig will be sent to the process whose process ID is equal to pid, subject to the ownership restrictions, above. pid may equal 1.

If pid is negative but not (pid_t)-1, sig will be sent to all processes whose process group ID is equal to the absolute value of pid and for which the process has permission to send a signal.

If pid is 0, sig will be sent to all processes excluding proc0 and proc1 whose process group ID is equal to the process group ID of the sender. Permission is needed to send a signal to process groups.

If pid is (pid_t)-1 and the sending process does not have the P_OWNER privilege, sig will be sent to all processes excluding proc0 and proc1 whose real user ID is equal to the effective user ID of the sender.

If pid is (pid_t)-1 and the sending process has the P_OWNER privilege, sig will be sent to all processes excluding proc0 and proc1.

Return values

On success, kill returns 0. On failure, kill returns -1, sets errno to identify the error, and sends no signal.

Errors

In the following conditions, kill fails and sets errno to:

EINVAL
sig is not a valid signal number.

EPERM
sig is SIGKILL and pid is (pid_t)1 (i.e., pid specifies proc1).

EPERM
The sending process does not have the P_OWNER privilege, the real or effective user ID of the sending process does not match the real or saved user ID of the receiving process, and the calling process is not sending SIGCONT to a process that shares the same session ID.

ESRCH
No process or process group can be found corresponding to that specified by pid. Also see ``Standards conformance'', below.

Standards conformance

The default behavior of kill conforms to X/Open System Headers and Interfaces, Volume 4, Issue 2.

The default behavior of kill is to fail with ESRCH if a process table entry is found matching pid, but that process is a zombie (a process that has exited, but whose entries have not yet been removed from system tables). Federal Information Processing Standard (FIPS) 151-2 requires that kill applied to a zombie process (or to a set of processes all of which are zombies) to succeed instead of failing with ESRCH. To get this behavior, change the PROCSET_ZOMBIES system tunable from ``0'' (the default value) to ``1'' and rebuild the kernel.

References

getpid(2), getsid(2), intro(2), kill(1), setpgrp(2), sigaction(2), signal(2), sigsend(2)

Notices

sigsend is a more versatile way to send signals to processes. The user is encouraged to use sigsend instead of kill.

Considerations for threads programming

Signals can be posted from one process to another via kill but not to specific threads within the receiving process. See signal(5) for further details. See thr_kill(3thread) for intra-process, thread-to-thread signaling.

Considerations for lightweight processes

Additionally, signals from one process cannot be addressed to specific LWPs in the receiving process.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004