Seth Woolley's Man Viewer

atexit(3) - atexit, atexit - register a function to be called at normal program termination - man 3 atexit

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

ATEXIT(3)                  Linux Programmer's Manual                 ATEXIT(3)



NAME
       atexit - register a function to be called at normal program termination

SYNOPSIS
       #include <stdlib.h>

       int atexit(void (*function)(void));

DESCRIPTION
       The atexit() function registers the given function to be called at nor-
       mal program termination, either via exit(3,n,1 builtins)(3) or via return from the pro-
       gram's main().  Functions so registered are called in(1,8) 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(3,n,1 builtins)  functions,  all  registrations
       are undone.

RETURN VALUE
       The  atexit()  function returns the value 0 if(3,n) successful; otherwise it
       returns a nonzero value.

EXAMPLE
       #include <stdio.h>
       #include <stdlib.h>
       #include <unistd.h>

       void bye(void) {
               printf(1,3,1 builtins)("That was all, folks\n");
       }

       int main(){
               long a;
               int i;

               a = sysconf(_SC_ATEXIT_MAX);
               printf(1,3,1 builtins)("ATEXIT_MAX = %ld(1,8)\n", a);

               i = atexit(bye);
               if(3,n) (i != 0) {
                       fprintf(stderr, "cannot set(7,n,1 builtins) exit(3,n,1 builtins) function\n");
                       return EXIT_FAILURE;
               }
               return EXIT_SUCCESS;
       }

CONFORMING TO
       SVID 3, BSD 4.3, ISO 9899, POSIX 1003.1-2001

SEE ALSO
       _exit(3), exit(3,n,1 builtins)(3), on_exit(3)



                                  2003-11-01                         ATEXIT(3)

References for this manual (incoming links)