explain_setpgrp_or_die(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– explain_setpgrp_or_die β€” Library Functions Manual πŸ’–

okay bestie, we're doing a libexplain one today β€” this is the explain_setpgrp_or_die(3) page, and it's literally about setting your process group and then screaming if it goes wrong. group-chat energy, let's go 🫢


✨ NAME ✨

explain_setpgrp_or_die β€” set process group and report errors πŸ’…


🌸 SYNOPSIS 🌸

#include <libexplain/setpgrp.h>

void explain_setpgrp_or_die(pid_t pid, pid_t pgid);
int explain_setpgrp_on_error(pid_t pid, pid_t pgid);

πŸ¦‹ DESCRIPTION πŸ¦‹

so explain_setpgrp_or_die is the function you call when you want to call the setpgrp(2) system call, but you want drama if it fails. like, on failure an explanation gets printed to stderr β€” and that explanation is obtained from the explain_setpgrp(3) function β€” and then the process terminates by calling exit(EXIT_FAILURE). gone. not coming back. periodt πŸ’€

meanwhile explain_setpgrp_on_error is the chill sibling: it also calls the setpgrp(2) system call, and on failure it also prints an explanation to stderr (again obtained from explain_setpgrp(3)), but it still returns to the caller. no exit, no vanishing act, you get to keep going ✨

here are the args, no cap:

  • pid β€” the pid, exactly as to be passed to the setpgrp(2) system call.
  • pgid β€” the pgid, exactly as to be passed to the setpgrp(2) system call.
⚠️ note bestie: the setpgrp(2) function has two implementations. the System V version has no arguments, while the BSD version has two arguments. for simplicity of implementation, the argument list you see here includes the pid and pgid arguments.

and the tea on that: the System V getpgid() semantics can be obtained by calling setpgrp(0, 0) on systems with the BSD version β€” and this is the API for libexplain, even on systems that do not use the BSD API. iconic, honestly πŸ‘‘


🌈 RETURN VALUE 🌈

explain_setpgrp_or_die only returns on success β€” see setpgrp(2) for more info. on failure, it prints an explanation and exits. it does not return. that's the whole vibe. πŸ’…

explain_setpgrp_on_error always returns the value returned by the wrapped setpgrp(2) system call. always. every time. 🫢


πŸŽ€ EXAMPLE πŸŽ€

the explain_setpgrp_or_die function is intended to be used in a fashion similar to the following example:

explain_setpgrp_or_die(pid, pgid);

that's it, that's the whole glow-up ✨


πŸ”₯ SEE ALSO πŸ”₯


libexplain version 1.4 Copyright (C) 2011 Peter Miller


okay and that's the whole page, bestie 🧚✨ this was explain_setpgrp_or_die(3) from the Library Functions Manual, and the sign-off tea is: libexplain version 1.4, copyright 2011 Peter Miller β€” go set that process group, you absolute main character πŸ‘‘πŸ’–πŸŒΈ

πŸ“¦ where this page comes from