Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
 ExitProcess Function
ExitProcess Function

Ends the calling process and all its threads.

Syntax

VOID WINAPI ExitProcess(
  __in  UINT uExitCode
);

Parameters

uExitCode [in]

The exit code for the process and all threads.

Return Value

This function does not return a value.

Remarks

Use the GetExitCodeProcess function to retrieve the process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value.

Exiting a process causes the following:

  1. All of the threads in the process, except the calling thread, terminate their execution.
  2. The entry-point functions of all loaded dynamic-link libraries (DLLs) are called with DLL_PROCESS_DETACH.
  3. After all attached DLLs have executed any process termination code, the ExitProcess function terminates the current process, including the calling thread.
  4. All of the object handles opened by the process are closed.
  5. The states of all threads of the process become signaled, satisfying any threads that had been waiting for the threads to terminate.
  6. The termination status of the process changes from STILL_ACTIVE to the exit value of the process.
  7. The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate.

If one of the terminated threads in the process holds a lock and the DLL detach code in one of the loaded DLLs attempts to acquire the same lock, then calling ExitProcess results in a deadlock. In contrast, if a process terminates by calling TerminateProcess, the DLLs that the process is attached to are not notified of the process termination. Therefore, if you do not know the state of all threads in your process, it is better to call TerminateProcess than ExitProcess. Note that returning from the main function of an application results in a call to ExitProcess.

Calling ExitProcess in a DLL can lead to unexpected application or system errors. Be sure to call ExitProcess from a DLL only if you know which applications or system components will load the DLL and that it is safe to call ExitProcess in this context.

Exiting a process does not cause child processes to be terminated.

Exiting a process does not necessarily remove the process object from the operating system. A process object is deleted when the last handle to the process is closed.

Examples

For an example, see Creating a Child Process with Redirected Input and Output.

Requirements

Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
Header

Declared in Winbase.h; include Windows.h.

Library

Use Kernel32.lib.

DLL

Requires Kernel32.dll.

See Also

CreateProcess
CreateRemoteThread
CreateThread
ExitThread
GetExitCodeProcess
GetExitCodeThread
OpenProcess
Process and Thread Functions
Processes
TerminateProcess
Terminating a Process


Send comments about this topic to Microsoft

Build date: 8/7/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker