ATEXIT(3P)
πΈ ATEXIT β the POSIX girlies' guide πΈ
okay bestie, welcome to ATEXIT(3P), straight out of the POSIX Programmer's Manual π this is the page about registering a function to run at process termination. yes it's as dramatic as it sounds. let's get into it π«Ά
β¨ PROLOG β¨
real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, consult the corresponding Linux manual page for details of Linux behavior), or honestly the interface may not be implemented on Linux at all π. vibe check accordingly.
π NAME π
atexit β register a function to run at process termination
π SYNOPSIS π
#include <stdlib.h>
int atexit(void (*func)(void));
π¦ DESCRIPTION π¦
so the functionality described on this reference page is aligned with the ISO C standard. any conflict between the requirements described here and the ISO C standard is unintentional, okay, nobody's fighting. this volume of POSIX.1β2017 defers to the ISO C standard. periodt.
the atexit() function shall register the function pointed to by func, to be called without arguments at normal program termination. at normal program termination, all functions registered by the atexit() function shall be called, in the reverse order of their registration β it's giving stack, it's giving LIFO, iconic behavior honestly β except that a function is called after any previously registered functions that had already been called at the time it was registered. yeah, read that one twice, it matters π
normal termination occurs either by a call to exit() or a return from main().
at least 32 functions can be registered with atexit().
and here's the plot twist: after a successful call to any of the exec functions, any functions previously registered by atexit() shall no longer be registered. gone. deleted. not me losing all my callbacks π«
π₯ RETURN VALUE π₯
upon successful completion, atexit() shall return 0; otherwise, it shall return a non-zero value. no in-between, no maybe, it's binary bestie π
π ERRORS π
no errors are defined. none. zero. the girlies are unbothered β¨
the following sections are informative.
π EXAMPLES π
none. we're keeping it mysterious π
π APPLICATION USAGE π
- the functions registered by a call to
atexit()must return to ensure that all registered functions are called. do not ghost them. - the application should call
sysconf()to obtain the value of{ATEXIT_MAX}, the number of functions that can be registered. there is no way for an application to tell how many functions have already been registered withatexit(). tragic, truly. - since the behavior is undefined if the
exit()function is called more than once, portable applications callingatexit()must ensure that theexit()function is not called at normal process termination when all functions registered by theatexit()function are called. - all functions registered by the
atexit()function are called at normal process termination, which occurs by a call to theexit()function or a return frommain()or on the last thread termination, when the behavior is as if the implementation calledexit()with a zero argument at thread termination time. - if, at normal process termination, a function registered by the
atexit()function is called and a portable application needs to stop furtherexit()processing, it must call the_exit()function or the_Exit()function or one of the functions which cause abnormal process termination. dramatic exit, only when necessary π
πΈ RATIONALE πΈ
none.
β FUTURE DIRECTIONS β
none.
π SEE ALSO π
exec, exit(), sysconf()
The Base Definitions volume of POSIX.1β2017, <stdlib.h>
π§ COPYRIGHT π§
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 .
and that's the whole page, bestie π this one's brought to you by IEEE/The Open Group, 2017, and the page you just read is ATEXIT(3P) π now go register those functions, in order, and remember: reverse order on the way out. slay. β¨π¦
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms