![]() -> Click here to learn how to get live help <- |
ATEXITIndexNAMEatexit - register a function to be called at normal program terminationSYNOPSIS#include <stdlib.h> int atexit(void (*function)(void)); DESCRIPTIONThe fBatexit()fP function registers the given fIfunctionfP to be called at normal program termination, either via exit(3) or via return from the program's fBmainfP(). Functions so registered are called in the reverse order of their registration; no arguments are passed.At least ATEXIT_MAX functions can be registered. This value is at least 32. It can be obtained using sysconf(3). By a successful call to one of the exec functions, all registrations are undone. RETURN VALUEThe fBatexit()fP function returns the value 0 if successful; otherwise it returns a nonzero value.EXAMPLE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void bye(void) {
printf("That was all, folksen");
}
int main(){
long a;
int i;
a = sysconf(_SC_ATEXIT_MAX);
printf("ATEXIT_MAX = %lden", a);
i = atexit(bye);
if (i != 0) {
fprintf(stderr, "cannot set exit functionen");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
CONFORMING TOSVID 3, BSD 4.3, ISO 9899, POSIX 1003.1-2001SEE ALSOexit(3), _exit(3), on_exit(3)
Index |