Export (0) Print
Expand All
and
div
eof
not
or
xor
Expand Minimize

exit, _exit

Terminates the calling process—exit terminates it after cleanup; _exit terminates it immediately.

Note Note

Do not use this method to shut down a Windows Store app, except in testing or debugging scenarios. Programmatic or UI ways to close a Windows Store app are not permitted according to Section 3.6 of the Windows 8 app certification requirements. For more information, see Application lifecycle (Windows Store apps).

void exit( 
   int status 
);
void _exit( 
   int status 
);

status

Exit status.

The exit and _exit functions terminate the calling process. exit calls—in last-in-first-out (LIFO) order—the functions that are registered by atexit and _onexit, and then flushes all file buffers before it terminates the process. _exit terminates the process without processing atexit or _onexit and without flushing stream buffers. Typically, the status value is set to 0 to indicate a normal exit or 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. exit, _exit, _cexit, and _c_exit behave 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.

When you call the exit or _exit function, the destructors for any temporary or automatic objects that exist at the time of the call are not called. An automatic object is defined in a function where the object is not declared to be static. A temporary object is an object that's created by the compiler. To destroy an automatic object before you call exit or _exit, explicitly call the destructor for the object, as follows:

myObject.myClass::~myClass();

Do not use DLL_PROCESS_ATTACH to call exit from DllMain. If you want to exit the DLLMain function, return FALSE from DLL_PROCESS_ATTACH.

Function

Required header

exit

<process.h> or <stdlib.h>

_exit

<process.h> or <stdlib.h>

For additional compatibility information, see Compatibility.

// crt_exit.c
// This program returns an exit code of 1. The
// error code could be tested in a batch file.


#include <stdlib.h>

int main( void )
{
   exit( 1 );
}
Show:
© 2014 Microsoft