kill()

NAME

kill() - send signal to a process

SYNOPSIS

#include <signal.h>

int kill (pid_t pid, int sig)

DESCRIPTION

The kill(2) function sends the signal given by sig to pid, a process or a group of processes. Sig may be one of the signals specified for sigaction(2) or it may be 0. If sig is 0, error checking is performed but no signal is actually sent. (This can be used to check the validity of pid.)

For a process to have permission to send a signal to the process pid, the real or effective user ID of the receiving process must match the real or effective user ID of the sending process or the user must have appropriate privileges. These user ID tests are not applied when sending SIGCONT to a process that is a member of the same session as the sending process.

If pid > 0:
Sig is sent to the process whose ID is equal to pid.
If pid = 0:
Sig is sent to all processes whose group ID is equal to the process group ID of the sender, and for which the process has permission.
If pid = -1:
Sig is sent to all processes for which the process has permission to send that signal.
If pid < -1:
Sig is sent to all processes whose group ID is equal to the absolute value of pid, and for which the process has permission.

The kill(2) function only delivers signals to processes in the Interix subsystem (that is, POSIX processes), not to Win32 processes. If you attempt to kill(2) a process which has exec(2)ed a Win32 process, the signal isn't delivered to the Win32 process.

RETURN VALUES

Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error.

ERRORS

The kill(2) call will fail and no signal will be sent if:

[EINVAL]
Sig is not a valid signal number.
[ESRCH]
No process can be found corresponding to that specified by pid.
[EPERM]
The effective user ID of the sending process does not match the effective user-id of the receiving process. When signaling a process group, this error is returned if any members of the group could not be signaled.

NOTES

To use the kill(2) function to send a signal to a process that does not have the same real/effective UID as the calling process, the calling process must have one of these Windows privileges:

SE_SECURITY_NAME
Required to use renamewtmpx(2) or mvwtmpx(1), or to use the (previously undocumented) command:
$ kill 1
to cause the Interix subsystem to re-read updated values in the registry without rebooting.
SE_TCB_NAME
Required if the calling process does not already have SE_SECURITY_NAME.

Only one is required to send a signal to a process with a different real/effective UID than the calling process, but SE_SECURITY_NAME does confer additional privileges.

SEE ALSO

getpid(2)

getpgrp(2)

sigaction(2)

privileges(5)