kill()

kill process 

Function


SYNOPSIS

#include <sys/types.h>

#include <signal.h>

int kill(pid_t pid, int sig);


DESCRIPTION

The kill() function sends a signal to a process or a group of processes that pid specifies. The signal to be sent is specified by sig, and is either one of the signals specified in signal.h, or 0. If sig is zero (the null signal), error checking is performed but no signal is actually sent. The null signal can be used to check the validity of pid.

For a process to have permission to send a signal to a pid-designated process, the real or effective user ID of the sending process must match the real or saved user ID of the receiving process. The exception is if the sending process has appropriate privileges. The process with ID 0 and the process with ID 1 are special processes. They are referred to as proc0 and proc1, respectively.

If the value of pid causes sig to be generated for the sending process and if sig is not blocked, either sig or at least one pending unblocked signal is delivered to the sending process before the kill() function returns.

kill() is successful if the process has permission to send sig to any of the processes that pid specified. If kill() fails, no signal is sent.


PARAMETERS

pid 

Is a process ID or process group ID.

sig 

Specifies the signal to be sent.


RETURN VALUES

If successful, kill() returns a value of zero. On failure, it returns a value of -1, does not send a signal, and sets errno to one of the following values:

EINVAL 

The value of sig is an invalid or unsupported signal number.

EPERM 

The user ID of the sending process is not privileged; its real or effective user ID does not match the real or saved user ID of the receiving process. Or, the process does not have permission to send the signal to any receiving process.

ESRCH 

No process or process group can be found that corresponds to the one that pid specifies.


CONFORMANCE

POSIX.1 (1996), with exceptions.


MULTITHREAD SAFETY LEVEL

Async-signal-safe.


PORTING ISSUES

The determination of whether the sending process has permission to send a signal to the receiving process ignores any uid or gid settings that have been specified with calls to setuid() or setgid(). The determination is done by comparing the uids of each of the two processes at the time that they were created.

Using kill() to send the SIGTERM or SIGHUP signal to a non-NuTCRACKER Platform process attempts to post a close message to a window owned by the process specified by pid. If the process calling kill() does not have sufficient privileges to perform this function, or if no window could be found to which to post the close message, kill() returns -1 with errno set to EPERM.

Sending the SIGKILL signal to non-NuTCRACKER Platform processes also attempts to post a close message to a window owned by the process specified by pid. In cases where it is not possible to post this message, or where the process does not exit in a timely fashion, kill() then attempts to use the Win32 TerminateProcess() function to kill the process specified by pid. If the process calling kill() does not have sufficient privileges to perform this function, kill() returns -1 with errno set to EPERM.

Sending any other signal to a non-NuTCRACKER Platform process fails with errno set to EPERM.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

api_intro

Functions:
getpgrp(), getpid(), killpg(), setpgrp(), setsid(), sigaction(), signal(), sigqueue()


PTC MKS Toolkit 10.4 Documentation Build 39.