TCGETPGRP(3POSIX)

πŸ’– TCGETPGRP(3POSIX) β€” the POSIX Programmer's Manual, bestie edition πŸ’–

okay so before we even start, you should know this page lives in the POSIX Programmer's Manual (that's the whole manual name, no cap). Heads up though: the Linux implementation of this interface may differ from what's written here β€” so if you're on Linux, go check the corresponding Linux manual page for the details of Linux behavior. Or like… the interface might not even be implemented on Linux at all. πŸ™ˆ So vibe check your platform first, fr fr.


✨ PROLOG ✨

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.

not me repeating myself but this is literally important okay 😭

πŸŽ€ NAME πŸŽ€

tcgetpgrp β€” get the foreground process group ID

like. it gets you the foreground process group ID. that's the whole job. iconic behavior honestly πŸ‘‘


🌸 SYNOPSIS 🌸

#include <unistd.h>

pid_t tcgetpgrp(int fildes);

so you include <unistd.h>, and you hand it a fildes (an int, bestie), and it gives you back a pid_t. simple. clean. slay. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

The tcgetpgrp() function shall return the value of the process group ID of the foreground process group associated with the terminal. πŸ’–

If there is no foreground process group, tcgetpgrp() shall return a value greater than 1 that does not match the process group ID of any existing process group. (yes, greater than 1. not 0, not 1. keep up 🫢)

The tcgetpgrp() function is allowed from a process that is a member of a background process group β€” so background besties can still call it, periodt. However, the information may be subsequently changed by a process that is a member of a foreground process group. so like… the answer you got might be stale by the time you blink. the foreground crew can just rewrite reality on you. it's giving main character energy vs background character energy ngl 😭


🌈 RETURN VALUE 🌈

Upon successful completion, tcgetpgrp() shall return the value of the process group ID of the foreground process associated with the terminal. πŸŽ‰

Otherwise, -1 shall be returned and errno set to indicate the error. (yeah, the classic -1 + errno combo, you know the drill)


πŸ’€ ERRORS πŸ’€

The tcgetpgrp() function shall fail if:

  • EBADF β€” The fildes argument is not a valid file descriptor. bestie that is not a file descriptor, what are you doing πŸ™ˆ
  • ENOTTY β€” The calling process does not have a controlling terminal, or the file is not the controlling terminal. no terminal, no vibes, no service 🚫

The following sections are informative. (translation: the juicy part is over, everything below is lore ✨)


πŸ“ EXAMPLES πŸ“

None.

literally none. the examples section said "not today" and went back to sleep 😴

🧚 APPLICATION USAGE 🧚

None.

also none!! two for two on the empty sections, we love a minimalist queen πŸ’…

πŸ’œ RATIONALE πŸ’œ

None.

none again. the rationale is giving mysterious. iykyk πŸŽ€

⭐ FUTURE DIRECTIONS ⭐

None.

none. the future is… unspecified. manifesting nothing changes for us πŸ™

πŸ”₯ SEE ALSO πŸ”₯

  • setsid()
  • setpgid()
  • tcsetpgrp()

The Base Definitions volume of POSIX.1‐2017, <sys_types.h>, <unistd.h>

go read those if you want the full cinematic universe. this is the crossover episode 🫢

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. 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 .

so basically: if this page and the actual Standard disagree, the Standard wins. no contest. the Standard is the referee and it does not take notes from me πŸ’…

and that's the whole page bestie!! this one came from IEEE/The Open Group, 2017, filed under TCGETPGRP(3POSIX) β€” go forth and get those foreground process group IDs, you absolute legend πŸŽ€βœ¨πŸ¦‹πŸ’–