EXIT(2)

πŸ’… EXIT(2) β€” System Calls Manual πŸ’…

okay bestie, sit DOWN, because we're talking about _exit from section 2 of the manual, and honestly? it's giving "the final boss of process life cycles." πŸ¦‹


✨ NAME ✨

_exit β€” terminate the calling process πŸ’€

no like. that's it. that's the whole job. iconic behavior fr fr.


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc)

so you just link it like a normal person and you're good 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <unistd.h>

void
_exit(int status);

🌸 DESCRIPTION 🌸

The _exit() system call terminates a process, and it comes with a whole little consequence list, so let's get into it, bestie, because this is NOT a "just vibe and leave" situation:

  • All of the descriptors open in the calling process are closed. This may entail delays, for example, waiting for output to drain; a process in this state may not be killed, as it is already dying. like… you cannot kill what is already leaving. it's in its departure era. periodt. πŸ’…
  • If the parent process of the calling process has an outstanding wait(2) call or catches the SIGCHLD signal, it is notified of the calling process's termination and the status is set as defined by wait(2). πŸ’Œ so your parent gets the text message.
  • The parent process-ID of all of the calling process's existing child processes are set to the process-ID of the calling process's reaper; the reaper (normally the initialization process) inherits each of these processes (see procctl(2), init(8) and the β€œDEFINITIONS” section of intro(2)). 🧚 so your kids get adopted, no cap.
  • If the termination of the process causes any process group to become orphaned (usually because the parents of all members of the group have now exited; see β€œorphaned process group” in intro(2)), and if any member of the orphaned group is stopped, the SIGHUP signal and the SIGCONT signal are sent to all members of the newly-orphaned process group. πŸ”₯ ok dramatic but necessary.
  • If the process is a controlling process (see intro(2)), the SIGHUP signal is sent to the foreground process group of the controlling terminal, and all current access to the controlling terminal is revoked. πŸ‘‘ rip to the terminal access, it's gone, it's deleted.

Most C programs call the library routine exit(3), which flushes buffers, closes streams, unlinks temporary files, etc., before calling _exit().

bestie PLEASE remember this. exit(3) is the one that tidies up first. _exit() is the one that just πŸƒβ€β™€οΈπŸ’¨ leaves immediately. iykyk.

⭐ RETURN VALUES ⭐

The _exit() system call can never return. 😭

literally cannot. it's not being rude, it's just physically incapable. once you call it you're gone, that's the whole bit. no return value, no comeback, no redemption arc. πŸ’€


πŸ¦‹ SEE ALSO πŸ¦‹

fork(2), sigaction(2), wait(2), exit(3), init(8)

(the whole friend group, honestly 🫢)


🌈 STANDARDS 🌈

The _exit() system call is expected to conform to ISO/IEC 9945-1:1990 (β€œPOSIX.1”). ✨


πŸ’œ HISTORY πŸ’œ

The _exit() function appeared in Version 7 AT&amp;T UNIX. so it's a legacy queen, an OG, we stan a function with lore. πŸŽ€


okay that's the whole page bestie!! this one came from the Debian peeps, dated September 8, 2016, and it lives at EXIT(2) in the System Calls Manual β€” mwah, take care of your processes, love u, bye!! πŸ’–πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from