[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Base Operating System and Extensions Technical Reference, Volume 1

exit, atexit, 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;
#include <sys/limits.h>
int atexit (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:

Parameters

Status Indicates the status of the 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.

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

Related Information

The acct subroutine, lockfx, lockf, or flock subroutines, sigaction, sigvec, or signal subroutine, times subroutine, wait, waitpid, or wait3 subroutine.

Asynchronous I/O Overview in AIX Version 4.3 Kernel Extensions and Device Support Programming Concepts.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]