Exit handlers
Sometimes, an application needs to automatically perform some operations on process termination.
#include <stdlib.h>
int atexit(void (*func)(void)); /* Returns 0 on success, or nonzero on error */
In case you need the exit status code, there's a nonstandard alternative provided by glibc
#define _BSD_SOURCE /* Or: #define _SVID_SOURCE */
#include <stdlib.h>
int on_exit(void (*func)(int, void *), void *arg); /* Returns 0 on success, or nonzero on error */