EXITS(3)
πΈ EXITS(3): terminate process, process cleanup πΈ
okay bestie, this is EXITS(3) from the Library Functions Manual, and it's literally the whole "how do we end a process without it being a whole thing" saga. the main characters are exits, _exits, exitcode, atexit, and atexitdont β and yes, they all ate π
β¨ SYNOPSIS β¨
#include <u.h>
#include <libc.h>
void _exits(char *msg)
void exits(char *msg)
int exitcode(char *msg)
int atexit(void(*)(void))
void atexitdont(void(*)(void))
π¦ DESCRIPTION π¦
exits is the conventional way to terminate a process β the classic, the standard, the moment. _exits also terminates a process, but it does not call the registered atexit handlers (q.v.). and bestie, neither of them can ever return. like ever. periodt.
msg conventionally includes a brief explanation of why we're exiting β maximum length ERRLEN β or you can pass a null pointer or an empty string to indicate normal termination. that string gets passed to the parent process when the parent does a wait(3), prefixed by the name and process id of the exiting process. so the parent knows exactly who left the group chat and why π
before calling _exits with msg as an argument, exits calls all the functions recorded by atexit β in reverse order. iconic behavior honestly.
atexit records fn as a function to be called by exits. it returns zero if it failed, and nonzero otherwise. a typical use is registering a cleanup routine for an I/O package. and to simplify programs that fork or share memory, exits only calls those atexit-registered functions that were registered by the same process as the one calling exits. no crossover episodes π«Ά
calling atexit twice (or more) with the same function argument causes exits to invoke the function twice (or more). double the function, double the chaos, no cap.
there is a limit to the number of exit functions that will be recorded; atexit returns 0 if that limit has been reached. so don't try to register your entire contact list, bestie π
atexitdont cancels a previous registration of an exit function. it's the "never mind, take me out of the will" of exit handlers.
π SOURCE π
/src/lib9/atexit.c/src/lib9/_exits.c
π SEE ALSO π
π BUGS π
because of limitations of Unix, the exit status of a process can only be an 8-bit integer. so that's a thing. exits and _exits treat null or empty exit status as exit code 0 and call exitcode to translate any other string into an exit code. by default, the library provides an exitcode that maps all messages to 1. applications may find it useful to provide their own implementations of exitcode.
exit codes 97 through 99 are used by the thread library to signal internal synchronization errors between the main program and a proxy process that implements backgrounding. so if you see those, it's giving thread drama, not your fault πΈ
to avoid name conflicts with the underlying system, atexit and atexitdont are preprocessor macros defined as p9atexit and p9atexitdont; see intro(3).
lowkey important: these are macros, bestie. don't forget it. iykyk π
kisses, this was EXITS(3) from the Library Functions Manual β source lives at /src/lib9/atexit.c and /src/lib9/_exits.c. the original footer didn't give a date and i am not inventing one, so consider this your cute little sign-off: stay terminating processes correctly, bestie πβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms