Share via


ExitProcess (Compact 2013)

3/28/2014

This function ends a process and all of its threads.

Syntax

VOID ExitProcess(
  UINT uExitCode
);

Parameters

  • uExitCode
    [in] Specifies the exit code for the process and for all threads that are terminated as a result of this call.

    To retrieve the process's exit value, use the GetExitCodeProcess function.

    To retrieve a thread's exit value, use the GetExitCodeThread function.

Return Value

None.

Remarks

This function is the preferred method of ending a process because it provides a clean process shutdown. This includes calling the entry-point function of all attached DLLs with a value indicating that the process is detaching from the DLL.

After all attached DLLs have executed a process termination value, this function terminates the current process.

The following actions are caused by terminating a process:

  • All object handles that were opened by the process are closed.
  • All threads in the process terminate their execution.
  • The state of the process object becomes signaled, satisfying threads waiting for the process to terminate.
  • The states of all threads of the process become signaled, satisfying threads waiting for the threads to terminate.
  • The termination status of the process changes from STILL_ACTIVE to the exit value of the process.

Terminating a process does not necessarily remove the process object from the OS. A process object is deleted when the last handle to the process is closed.

A process that is started as a result of a call by CreateProcess is run serially with the ExitProcess, ExitThread, and CreateThread functions. Within the parent process, only one of these events can happen in an address space at a time.

The following list shows the restrictions during the process:

  • During process startup and DLL initialization routines, new threads can be created, but they do not begin execution until DLL initialization is done for the process.
  • In a process, only one thread at a time can be in a DLL initialization or detach routine.
  • ExitProcess does not return to processes in the DLL initialization or detach routine.

Requirements

Header

windows.h

Library

coredll.lib

See Also

Reference

Process and Thread Functions
CreateProcess
CreateThread
ExitThread
GetExitCodeProcess
GetExitCodeThread
OpenProcess
TerminateProcess