killpg() — Send a signal to a process group

Standards

Standards / Extensions C or C++ Dependencies
XPG4.2
Single UNIX Specification, Version 3
both
POSIX(ON)

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <signal.h>

int killpg(pid_t pgrp, int sig);

General description

The killpg() function sends a signal to a process group.

A process has permission to send a signal if the real or effective user ID of the sender is the same as the real or effective user ID of the intended recipient. A process can also send signals if it has appropriate privileges. If _POSIX_SAVED_IDS is defined in the <unistd.h> include file, the saved set user ID of the intended recipient is checked instead of its effective user ID.

Regardless of user ID, a process can always send a SIGCONT signal to a process group that is a member of the same session (same session ID) as the sender.
pid_t pgrp;
Specifies the process group that the caller wants to send a signal to:
  • If pgrp is greater than one, killpg() sends the signal, sig, to the process whose process group ID is equal to pgrp and which the sender has appropriate privileges to send a signal.
  • If pgrp is equal to or less than one, killpg() returns a -1 and sets errno to EINVAL.
int sig;
The signal that should be sent to the processes specified by pid. (For a list of signals, see Table 1.) This must be zero, or one of the signals defined in the <signal.h> include file. If sig is zero, killpg() performs error checking but doesn't really send a signal. You can code sig as zero to check whether the pid argument is valid.

This function is supported only in a POSIX program.

Usage notes

The use of the SIGTHSTOP and SIGTHCONT signal is not supported with this function.

Returned value

If successful, killpg() returns 0 if it has permission to send sig to any of the processes in the process group ID specified by pgrp.

If unsuccessful, killpg() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
The value of sig is incorrect or is not the number of a supported signal, or the value of pgrp is less than or equal to one.
EPERM
The caller does not have permission to send the signal to any process in the process group ID specified by pgrp.
ESRCH
There are no process groups corresponding to pgrp.

Related information