User Tools

Site Tools




atexit, at_quick_exit - register a function to run at process termination or object unloading


#include <stdlib.h>

int atexit(void (*func)(void));

int at_quick_exit(void (*func)(void));


The atexit() function registers the function pointed to by func to be called without arguments on normal termination of the program or when the object defining the function is unloaded.

Normal termination occurs by either a call to the exit(3C) function or a return from main(). Object unloading occurs when a call to dlclose(3C) results in the object becoming unreferenced.

The at_quick_exit() function registers the function pointed to by func. That function is then called without arguments if the quick_exit() function is called.

An at_quick_exit() registered function is not called when the object defining the function is unloaded. Rather, it is simply removed from the at_quick_exit() registration list.

The at_quick_exit() function registrations are distinct from the atexit() registrations, so applications may need to call both registration functions with the same argument.

The number of functions that may be registered with atexit() or at_quick_exit() is limited only by available memory (refer to the _SC_ATEXIT_MAX argument of sysconf(3C)).

After a successful call to any of the exec(2) functions, any functions previously registered by atexit() or at_quick_exit() are no longer registered.

On process exit, functions are called in the reverse order of their registration. On object unloading, any atexit() functions belonging to an unloadable object are called in the reverse order of their registration.


Upon successful completion, the atexit() and at_quick_exit() functions return 0. Otherwise, they return a non-zero value and set errno to indicate the reason.


The atexit() and at_quick_exit() functions may fail if:


Insufficient storage space is available.


The functions registered by a call to atexit() or at_quick_exit() must return to ensure that all registered functions are called.

There is no way for an application to tell how many functions have already been registered with atexit() or at_quick_exit().


See attributes(7) for descriptions of the following attributes:


The at_quick_exit() function is specified in the C11 standard (INCITS/ISO/IEC 9899:2011).


exec(2), dlclose(3C), exit(3C), sysconf(3C), attributes(7)

solaris/atexit.3c.txt · Last modified: 2023/07/19 08:57 by A User Not Logged in