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 GetExitCodeProcess1 function to retrieve the process's exit value. Use the GetExitCodeThread2 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 without receiving a DLL_THREAD_DETACH notification.
  2. The states of all of the threads terminated in step 1 become signaled.
  3. The entry-point functions of all loaded dynamic-link libraries (DLLs) are called with DLL_PROCESS_DETACH.
  4. After all attached DLLs have executed any process termination code, the ExitProcess function terminates the current process, including the calling thread.
  5. The state of the calling thread becomes signaled.
  6. All of the object handles opened by the process are closed.
  7. The termination status of the process changes from STILL_ACTIVE to the exit value of the process.
  8. 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 TerminateProcess3, 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 Output4.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

CreateProcess5
CreateRemoteThread6
CreateThread7
ExitThread8
GetExitCodeProcess1
GetExitCodeThread2
OpenProcess9
Process and Thread Functions10
Processes11
TerminateProcess3
Terminating a Process12

 

 

Send comments about this topic to Microsoft13

Build date: 9/7/2011

Links Table
1http://msdn.microsoft.com/en-us/library/ms683189(v=vs.85).aspx
2http://msdn.microsoft.com/en-us/library/ms683190(v=vs.85).aspx
3http://msdn.microsoft.com/en-us/library/ms686714(v=vs.85).aspx
4http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx
5http://msdn.microsoft.com/en-us/library/ms682425(v=vs.85).aspx
6http://msdn.microsoft.com/en-us/library/ms682437(v=vs.85).aspx
7http://msdn.microsoft.com/en-us/library/ms682453(v=vs.85).aspx
8http://msdn.microsoft.com/en-us/library/ms682659(v=vs.85).aspx
9http://msdn.microsoft.com/en-us/library/ms684320(v=vs.85).aspx
10http://msdn.microsoft.com/en-us/library/ms684847(v=vs.85).aspx
11http://msdn.microsoft.com/en-us/library/ms682015(v=vs.85).aspx
12http://msdn.microsoft.com/en-us/library/ms686722(v=vs.85).aspx
13Send comments about this topic to Microsoft; mailto:wsddocfb@microsoft.com?subject=Documentation%20feedback%20%5Bprocthread%5Cbase%5D:%20ExitProcess%20function%20%20RELEASE:%20(9/7/2011)&body=%0A%0APRIVACY%20STATEMENT%0A%0AThe%20SDK%20team%20uses%20the%20feedback%20submitted%20to%20improve%20the%20SDK%20documentation.%20We%20do%20not%20use%20your%20email%20address%20for%20any%20other%20purpose.%20We%20will%20remove%20your%20email%20address%20from%20our%20system%20after%20the%20issue%20you%20are%20reporting%20has%20been%20resolved.%20While%20we%20are%20working%20to%20resolve%20this%20issue,%20we%20may%20send%20you%20an%20email%20message%20to%20request%20more%20information%20about%20your%20feedback.%20After%20the%20issues%20have%20been%20addressed,%20we%20may%20send%20you%20an%20email%20message%20to%20let%20you%20know%20that%20your%20feedback%20has%20been%20addressed.%0A%0AFor%20more%20information%20about%20Microsoft's%20privacy%20policy,%20see%20http://privacy.microsoft.com/en-us/default.aspx.
Community Content Add
Annotations FAQ