Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

atexit - register function to run at process termination

&pagelevel(4)&pagelevel

Syntax

#include <stdlib.h>

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

Description

atexit() registers a function func() to be called without arguments at normal process termination. The registered functions are called in the reverse order to that in which they
were registered. Functions for which multiple registrations exist are called more than once.

Functions registered with atexit() are called only if the process is terminated "normally" by one of the following methods:

  • an explicit exit() call

  • termination of the main function without an explicit exit call

    BS2000

  • Process termination by the C runtime system with exit(-1), i.e. on occurrence of a raise signal (not SIGABRT) which is handled by the default signal handling mechanism via SIG_DFL (see signal()) or not handled at all.

Up to 40 functions can be registered.

Following a successful call to any of the exec functions, all functions previously registered by atexit() will no longer be registered.

Return val.

0

!= 0

if the function is registered successfully.

if an error occurs.

Notes

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

The sysconf() function returns the value of ATEXIT_MAX, which specifies the total number of functions that can be registered. However, it is not possible to find out how many functions have already been registered (except by counting them).

See also

at_quick_exit(), bs2exit(), exit(), signal(), stdlib.h.