Export (0) Print
Expand All

exit, _exit

Visual Studio 6.0

Terminate the calling process after cleanup (exit) or immediately (_exit).

void exit( int status );

void _exit( int status );

Function Required Header Compatibility
exit <process.h> or <stdlib.h> ANSI, Win 95, Win NT
_exit <process.h> or <stdlib.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

None

Parameter

status

Exit status

Remarks

The exit and _exit functions terminate the calling process. exit calls, in last-in-first-out (LIFO) order, the functions registered by atexit and _onexit, then flushes all file buffers before terminating the process. _exit terminates the process without processing atexit or _onexit 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 calling process, if one exists, after the calling process exits. The status value is available to the operating-system batch command ERRORLEVEL and is represented by one of two constants: EXIT_SUCCESS, which represents a value of 0, or EXIT_FAILURE, which represents a value of 1. The behavior of exit, _exit, _cexit, and _c_exit is as follows.

Function Description
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 the caller, but does not terminate the process.
_c_exit Performs “quick” C library termination procedures and returns to the caller, but does not terminate the process.

Example

/* EXITER.C: This program prompts the user for a yes
 * or no and returns an exit 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 )
{
   int ch;

   _cputs( "Yes or no? " );
   ch = _getch();
   _cputs( "\r\n" );
   if( toupper( ch ) == 'Y' )
      exit( 1 );
   else
      exit( 0 );
}

Process and Environment Control Routines

See Also   abort, atexit, _cexit, _exec Function Overview, _onexit, _spawn Function Overview, system

Show:
© 2014 Microsoft