GETPGID(3P)

πŸ’– getpgid(3P) β€” the POSIX Programmer's Manual one πŸ’–

okay bestie, sit down, hydrate, because we're reading the POSIX Programmer's Manual page for getpgid(3P) and it is genuinely so much cuter than it looks. this is the POSIX spec version, not the Linux one, so like… pay attention to the next part, it's important.


🚨 PROLOG 🚨

so like, heads up before we even start:

this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. OR, plot twist, the interface might not even be implemented on Linux at all. πŸ™ˆ

not me warning you about platform differences in the prolog. it's giving responsible.

✨ NAME ✨

getpgid β€” get the process group ID for a process

(short, sweet, does exactly what it says on the tin. we love a name that doesn't lie. πŸ’…)


🌸 SYNOPSIS 🌸

#include <unistd.h>

pid_t getpgid(pid_t pid);

there she is. one include, one function, one pid_t in, one pid_t out. iconic. no cap.


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea:

the getpgid() function shall return the process group ID of the process whose process ID is equal to pid.

and if pid is equal to 0? bestie. that's the main character move. getpgid() shall return the process group ID of the calling process. it's like it looks in the mirror. self-love fr fr. πŸͺžβœ¨


πŸ’œ RETURN VALUE πŸ’œ

  • upon successful completion, getpgid() shall return a process group ID. slay.
  • otherwise, it shall return (pid_t)-1 and set errno to indicate the error. 😭
yes, that's (pid_t)-1, cast and everything. don't get cute with a plain -1, the manpage said what it said.

πŸ”₯ ERRORS πŸ”₯

the shall fail if list (these are the mandatory ones, no wiggle room)

  • EPERM β€” the process whose process ID is equal to pid is not in the same session as the calling process, and the implementation does not allow access to the process group ID of that process from the calling process.
different session AND no access granted? yeah that's a hard no from the kernel, bestie. 🚫
  • ESRCH β€” there is no process with a process ID equal to pid.
ghosted. literally. that PID does not exist. πŸ’€

the may fail if list (situational, depending on implementation)

  • EINVAL β€” the value of the pid argument is invalid.
"may" is doing a lot of heavy lifting here. some implementations care, some don't. vibe check accordingly.

πŸŽ€ EXAMPLES πŸŽ€

None.

(no examples. they said "figure it out." and honestly? fair. 😌)


🌈 APPLICATION USAGE 🌈

None.

(nothing to add. the manpage is a person of few words and I respect it deeply.)


⭐ RATIONALE ⭐

None.

(no rationale given. it just is. unbothered. unbothered queen energy. πŸ‘‘)


🧚 FUTURE DIRECTIONS 🧚

None.

(no plans to change it. it's perfect. periodt.)


πŸ’« SEE ALSO πŸ’«

go read these next, they're all in the same friend group:

  • exec
  • fork()
  • getpgrp()
  • getpid()
  • getsid()
  • setpgid()
  • setsid()

and from the Base Definitions volume of POSIX.1‐2017: <unistd.h> β€” yeah, that header again. it's the group chat everyone's in. πŸ“±


okay this part is the legal bit, so let's be respectful:

portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (translation: if there's a fight, the original wins. πŸ’―)

the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie. πŸ’– no notes, no drama, just a clean little process-group lookup. go forth and getpgid() responsibly. 🌸

this was the IEEE/The Open Group, 2017 edition of getpgid(3P) β€” mwah, thanks for reading, you ate. πŸ’…βœ¨

πŸ“¦ where this page comes from