[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


kill or killpg Subroutine

Purpose

Sends a signal to a process or to a group of processes.

Library

Standard C Library (libc.a)

Syntax

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


int kill(
Process,
Signal)
pid_t Process;
int Signal;


killpg(
ProcessGroup, Signal)
int ProcessGroup, Signal;

Description

The kill subroutine sends the signal specified by the Signal parameter to the process or group of processes specified by the Process parameter.

To send a signal to another process, either the real or the effective user ID of the sending process must match the real or effective user ID of the receiving process, and the calling process must have root user authority.

The processes that have the process IDs of 0 and 1 are special processes and are sometimes referred to here as proc0 and proc1, respectively.

Processes can send signals to themselves.

Note: Sending a signal does not imply that the operation is successful. All signal operations must pass the access checks prescribed by each enforced access control policy on the system.

Parameters


Process Specifies the ID of a process or group of processes.

If the Process parameter is greater than 0, the signal specified by the Signal parameter is sent to the process identified by the Process parameter.

If the Process parameter is 0, the signal specified by the Signal parameter is sent to all processes, excluding proc0 and proc1, whose process group ID matches the process group ID of the sender.

If the value of the Process parameter is a negative value other than -1 and if the calling process passes the access checks for the process to be signaled, the signal specified by the Signal parameter is sent to all the processes, excluding proc0 and proc1. If the user ID of the calling process has root user authority, all processes, excluding proc0 and proc1, are signaled.

If the value of the Process parameter is a negative value other than -1, the signal specified by the Signal parameter is sent to all processes having a process group ID equal to the absolute value of the Process parameter.

If the value of the Process parameter is -1, the signal specified by the Signal parameter is sent to all processes which the process has permission to send that signal.

If pid is -1, sig will be sent to all processes (excluding an unspecified set of system processes) for which the process has permission to send that signal.

Signal Specifies the signal. If the Signal parameter is a null value, error checking is performed but no signal is sent. This parameter is used to check the validity of the Process parameter.
ProcessGroup Specifies the process group.

Return Values

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

Error Codes

The kill subroutine is unsuccessful and no signal is sent if one or more of the following are true:

EINVAL The Signal parameter is not a valid signal number.
EINVAL The Signal parameter specifies the SIGKILL, SIGSTOP, SIGTSTP, or SIGCONT signal, and the Process parameter is 1 (proc1).
ESRCH No process can be found corresponding to that specified by the Process parameter.
EPERM The real or effective user ID does not match the real or effective user ID of the receiving process, or else the calling process does not have root user authority.

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

The following interface is provided for BSD Compatibility:

killpg(ProcessGroup, Signal)
int ProcessGroupSignal;

This interface is equivalent to:

if (ProcessGroup < 0)
{
  errno = ESRCH;
  return (-1);
}
return (kill(-ProcessGroup, Signal));

Related Information

The getpid, getpgrp, or getppid (getpid, getpgrp, or getppid Subroutine) subroutine, setpgid or setpgrp subroutine, sigaction, sigvec, or signal subroutine.

The kill command.

Signal Management in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs provides more information about signal management in multi-threaded processes.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]