Terminate the calling process after cleanup (exit) or immediately (_exit).
#include <process.h> | Required only for function declarations | |
#include <stdlib.h> | Use either PROCESS.H or STDLIB.H |
void exit( int status );
void _exit( int status );
status | Exit status |
The exit and _exit functions terminate the calling process. The exit function first calls, in LIFO (last-in–first-out) order, the functions registered by atexit and _onexit, then flushes all file buffers before terminating the process. The _exit function terminates the process without processing atexit or _onexit functions or flushing stream buffers. The status value is typically set to 0 to indicate a normal exit and set to some other value to indicate an error.
Although the exit and _exit calls do not return a value, the low-order byte of status is made available to the waiting parent process, if one exists, after the calling process exits. The status value is available to the operating-system batch command ERRORLEVEL.
The behavior of the exit, _exit, _cexit, and _c_exit functions is as follows:
Function | Action |
exit | Performs complete C library termination procedures, terminates the process, and exits with the supplied status code. |
_exit | Performs “quick” C library termination procedures, terminates the process, and exits with the supplied status code. |
_cexit | Performs complete C library termination procedures and returns to caller, but does not terminate the process. |
_c_exit | Performs “quick” C library termination procedures and returns to caller, but does not terminate the process. |
None.
exit
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN
32-Bit:DOS32X
_exit
Standards:None
16-Bit:DOS, QWIN, WIN
32-Bit:DOS32X
abort, atexit, _cexit, _exec functions, _onexit, _spawn functions, system
/* EXITER.C: This program prompts the user for a yes or no and returns
* a DOS error code of 1 if the user answers Y or y; otherwise it
* returns 0. The error code could be tested in a batch file.
*/
#include <conio.h>
#include <stdlib.h>
void main( void )
{
char ch;
_cputs( "Yes or no? " );
ch = _getch();
_cputs( "\r\n" );
if( toupper( ch ) == 'Y' )
exit( 1 );
else
exit( 0 );
}