exit, atexit, unatexit, _exit, or _Exit Subroutine

Purpose

Terminates a process.

Library

Standard C Library (libc.a)

Syntax

#include <stdlib.h>

void exit ( Status)
int Status;

void _exit ( Status)
int Status;

void _Exit (Status)
int Status;
#include <sys/limits.h>

int atexit ( Function)
void (*Function) (void);

int unatexit (Function)
void (*Function)(void);

Description

The exit subroutine terminates the calling process after calling the standard I/O library _cleanup function to flush any buffered output. Also, it calls any functions registered previously for the process by the atexit subroutine. The atexit subroutine registers functions called at normal process termination for cleanup processing. Normal termination occurs as a result of either a call to the exit subroutine or a return statement in the main function.

Each function a call to the atexit subroutine registers must return. This action ensures that all registered functions are called.

Finally, the exit subroutine calls the _exit subroutine, which completes process termination and does not return. The _exit subroutine terminates the calling process and causes the following to occur:

The _Exit subroutine is functionally equivalent to the _exit subroutine. The _Exit subroutine does not call functions registered with atexit or any registered signal handlers. The way the subroutine is implemented determines whether open streams are flushed or closed, and whether temporary files are removed. The calling process is terminated with the consequences described below.

The unatexit subroutine is used to unregister functions that are previously registered by the atexit subroutine. If the referenced function is found, it is removed from the list of functions that are called at normal program termination.

Parameters

Item Description
Status Indicates the status of the process. May be set to 0, EXIT_SUCCESS, EXIT_FAILURE, or any other value, though only the least significant 8 bits are available to a waiting parent process.
Function Specifies a function to be called at normal process termination for cleanup processing. You may specify a number of functions to the limit set by the ATEXIT_MAX function, which is defined in the sys/limits.h file. A pushdown stack of functions is kept so that the last function registered is the first function called.

Return Values

Upon successful completion, the atexit subroutine returns a value of 0. Otherwise, a nonzero value is returned. The exit and _exit subroutines do not return a value.

The unatexit() subroutine returns a value of 0 if the function referenced by Function is found and removed from the atexit list. Otherwise, a nonzero value is returned.