Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

kill - send signal to process or process group

&pagelevel(4)&pagelevel

Syntax

#include <signal.h>

Optional
#include <sys/types.h> (End)

int kill(pid_t pid, int sig);

Description

If the function is called with POSIX functionality, its behavior conforms with XPG4 as described below:

  • kill() sends a signal sig to a process or a group of processes specified by pid, where sig is either one from the list given in signal.h or 0. If sig is 0 (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.

  • {_POSIX_SAVED_IDS} is defined on all X/Open-conformant systems. For a process to have permission to send a signal to a process designated by pid, the real or effective user ID of the sending process must match the real or saved set-user-ID of the receiving process, unless the sending process has appropriate privileges.

  • If pid is greater than 0, sig is sent to the process whose process ID is equal to pid.

  • If pid is 0, sig is sent to all processes (excluding a number of system processes) whose process group ID is equal to the process group ID of the sender, and for which the process has permission to send a signal.

  • If pid is -1, sig is sent to all processes (excluding system processes) for which the process has permission to send that signal.

  • If pid is negative, but not -1, sig is 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 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 kill() returns.

  • No user ID test is applied when sending SIGCONT to a process that is a member of the same session as the sending process.

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

If threads are used, then the function affects the process or a thread in the following manner:

  • A signal is sent to a process or a process group; The following applies to the (special) case caused by the value of pid in which sig is generated for the sending process: If the signal is not blocked for the calling thread and all other threads of the process block the signal or do not wait for the signal in a sigwait() function, then sig (or at least a follow-up non-blocking signal) is sent to the sending thread before kill() returns.

BS2000

  • The following deviations in behavior must be noted if the function is called with BS2000 functionality:

  • pid must be 0, so the signal is sent to the calling process.

  • The following subset of the signals defined in signal.h can be used for sig:

    Signal

    STXIT class

    Meaning

    SIGHUP

    ABEND

    Disconnection of link to terminal

    SIGINT

    ESCPBRK

    Interrupt from the terminal with [K2]

    SIGILL

    PROCHK

    Execution of an invalid instruction

    SIGABRT

    -

    raise signal for program abort with _exit(-1)

    SIGFPE

    PROCHK

    Error in a floating-point operation

    SIGKILL

    -

    raise signal for program abort with exit(-1)

    SIGSEGV

    ERROR

    Memory access with invalid segment access

    SIGALRM

    RTIMER

    A time interval has elapsed (real time)

    SIGTERM

    TERM

    Signal at program termination

    SIGUSR1

    -

    Defined by the user

    SIGUSR2

    -

    Defined by the user

    SIGDVZ

    PROCHK

    Division by 0

    SIGXCPU

    RUNOUT

    CPU time has run out

    SIGTIM

    TIMER

    A time interval has elapsed (CPU time)

    SIGINTR

    INTR

    SEND-MESSAGE command

    (End)

Return val.

0

-1

upon successful completion.

if an error occurs. errno is set to indicate the error.

Errors

kill() will fail if: 

 

EINVAL

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

 

EPERM

The process does not have permission to send the signal to any receiving process.

BS2000
EPERM is not supported. (End)


ESRCH

No process or process group can be found corresponding to that specified by pid.

See also

 getpid(), raise(), setsid(), sigaction(), signal.h, sys/types.h.