GETPGRP(2)
β¨ GETPGRP(2) β¨
okay bestie, welcome to section 2 of the manual β the System Calls Manual π β and today's main character is getpgrp, the little syscall that tells you which process group you're in. no cap.
π NAME π
getpgrp β get process group π
π LIBRARY π
Standard C Library (libc, -lc) β she lives in libc, obviously π
πΈ SYNOPSIS πΈ
#include <unistd.h>
pid_t
getpgrp(void);
pid_t
getpgid(pid_t pid);
π¦ DESCRIPTION π¦
so here's the tea β β getpgrp() returns the process group of the current process. that's it, that's her whole job.
getpgid() is the more specific sister: she returns the process group of whatever process you point at with pid. and if pid is zero? getpgid() just hands you the process group of the current process instead, which is giving "I got you, bestie" π«Ά
now why do process groups even exist, you ask? two reasons, and they're both iconic:
- they're used for distribution of signals β like, signals get broadcast to a whole group at once, it's a whole group chat π£
- terminals use them to arbitrate requests for their input: processes that have the same process group as the terminal are foreground and they may read π. everybody else? they'll block with a signal if they even try to read. not me getting put in timeout by the tty π
this is why programs like csh(1) use this system call to create process groups while implementing job control. and for getting/setting the process group of the control terminal, you'd reach for tcgetpgrp() and tcsetpgrp() instead. iykyk β¨
π₯ RETURN VALUES π₯
getpgrp()always succeeds. no error path, no drama, she just ate πgetpgid()on a successful completion returns the process group of the process you specified. otherwise it returns a value of-1and setserrnoto indicate the error. the audacity π
π COMPATIBILITY π
okay so this version of getpgrp() differs from past Berkeley versions because she does not take a pid_t pid argument. is that a glow-up or a downgrade? not for us to decide β because this incompatibility is required by ISO/IEC 9945-1:1990 (βPOSIX.1β). periodt.
and here's the actual rationale straight from the ISO/IEC 9945-1:1990 (βPOSIX.1β) Rationale, quoted in full because receipts matter:
4.3BSD provides agetpgrp()system call 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 UNIXgetpgrp()suffices, and the added complexity of the 4.3BSDgetpgrp()has been omitted from POSIX.1. The old functionality is available from thegetpgid()system call.
so yeah β old behaviour didn't die, she just moved into getpgid(). glow-up fr fr π
π ERRORS π
the getpgid() system call will succeed unless:
[ESRCH]β there is no process whose process ID equalspid. bestie is not in the group chat, she does not exist, nothing to see π
π SEE ALSO π
β STANDARDS β
the getpgrp() system call is expected to conform to ISO/IEC 9945-1:1990 (βPOSIX.1β). slay, certified, standard-issue queen π
π HISTORY π
getpgrp()system call appeared in 4.0BSD β an OG, a legend, we stan πgetpgid()system call is derived from its usage in AT&T System V Release 4 UNIX. she's got lineage, bestie, she's royalty π
and that's the whole page, no notes π«Ά this one came from Debian and is dated June 4, 1993 β vintage, iconic, still relevant. take care of your process groups out there, mwah π β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms