atexit() - register a function to be called on exit
#include <stdlib.h>
int atexit (void (*function)(void))
The atexit(3) function registers the given function to be called at program exit, whether through exit(3) or through return from the program's main(). Functions so registered are called in reverse order; no arguments are passed. At least 32 functions can always be registered, and more are allowed as long as sufficient memory can be allocated.
On success, the atexit(3) function returns 0; on failure, it returns -1 and sets the value of errno
atexit(3) can generate the following error:
exit(3)