getpgid()

Updated: April 19, 2023

Get a process group ID

Synopsis:

#include <unistd.h>

pid_t getpgid( pid_t pid );

Arguments:

pid
The ID of the process whose process group ID you want to get.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The getpgid() returns the group ID for the process specified by pid. If pid is 0, getpgid() returns the calling process's group ID.

Note: In order to get the group ID of a process outside the calling process's session, your process must have the PROCMGR_AID_GETID ability enabled. For more information, see procmgr_ability().

The following definitions are worth mentioning:

Process
An executing instance of a program, identified by a nonnegative integer called a process ID.
Process group
A collection of one or more processes, with a unique process group ID. A process group ID is a positive integer.

Returns:

A process group ID for success, or (pid_t)-1 if an error occurred (errno is set).

Errors:

EPERM
The calling process doesn't have the required permission; see procmgr_ability().
ESRCH
The process specified by pid doesn't exist.

Classification:

POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes