---
name: "getpgrp"
section: "2"
platform: "macos"
package: "xnu"
version: "12377.121.6"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/getpgrp"
---

# getpgrp(2)

get process group

## NAME

**getpgid**, **getpgrp** – get process group

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<unistd.h\>**

*pid\_t*\

**getpgid**(*pid\_t pid*);

*pid\_t*\

**getpgrp**(*void*);

## DESCRIPTION

The process group of the current process is returned by **getpgrp**(). The process group of the process identified by *pid* is returned by **getpgid**(). If *pid* is zero, **getpgid**() returns the process group of the current process.

Process groups are used for distribution of signals, and by terminals to arbitrate requests for their input: processes that have the same process group as the terminal are foreground and may read, while others will block with a signal if they attempt to read.

This call is thus used by programs such as [csh(1)](/csh/1.md) to create process groups in implementing job control. The **tcgetpgrp**() and **tcsetpgrp**() calls are used to get/set the process group of the control terminal.

## RETURN VALUES

The **getpgrp**() call always succeeds. Upon successful completion, the **getpgid**() call returns the process group of the specified process; otherwise, it returns a value of -1 and sets *errno* to indicate the error.

## ERRORS

**getpgid**() will succeed unless:

- \[ESRCH\]

  There is no process whose process ID equals *pid*.

## SEE ALSO

[getsid(2)](/getsid/2.md), [setpgid(2)](/setpgid/2.md), [termios(4)](/termios/4.md)

## HISTORY

The **getpgrp**() function call appeared in 4.0BSD. The **getpgid**() function call is derived from its usage in System V Release 4.

## STANDARDS

The **getpgrp**() function call is expected to conform to ISO/IEC 9945-1:1990 (“POSIX.1”).

## COMPATIBILITY

This version of **getpgrp**() differs from past Berkeley versions by not taking a *pid\_t pid* argument. This incompatibility is required by ISO/IEC 9945-1:1990 (“POSIX.1”).

From the ISO/IEC 9945-1:1990 (“POSIX.1”) Rationale:

4\.3BSD provides a **getpgrp**() function that returns the process group ID for a specified process. Although this function is used to support job control, all known job-control shells always specify the calling process with this function. Thus, the simpler AT&T System V UNIX **getpgrp**() suffices, and the added complexity of the 4.3BSD **getpgrp**() has been omitted from POSIX.1. The old functionality is available from the **getpgid**() function.
