ExitProcess Function

The ExitProcess function terminates the calling process and all of its threads.

VOID ExitProcess(
  UINT uExitCode
);

Parameters

  • uExitCode [in]

    The status code for the process that is terminating. Use the return code conventions of the generic code return values:

    • STILL_ACTIVE (259): This value is reserved for the system and should not be used by applications.
    • 0: Indicates successful execution.
    • Any other value: Indicates an error or abnormal termination.

Return Value

This function does not return a value.

Remarks

The ExitProcess function causes the calling process to terminate. The process-initialization routine of the operating system is responsible for calling ExitProcess when the process-initialization routine determines that the process should terminate. When a process terminates, its threads are terminated, and the process is marked for deletion.

Note that this function is exported by kernel32.dll. Because ExitProcess terminates the process, it should not be called from a DLL. If a DLL must terminate a process, the DLL should not call ExitProcess; instead, it should cause the calling process to call ExitProcess.

ExitProcess performs the following actions:

  • Calls the exit routines registered by the process.
  • Calls the attached DLLs' process-detach notification routines.
  • Returns the exit code to the parent process.
  • Terminates the process and all of its threads.

Use the ExitThread function to terminate the calling thread but not the process.

Example

#include <windows.h>
#include <stdio.h>

int main() {
    printf("This process will now exit.\n");

    // Exit the process with a success code (0)
    ExitProcess(0);

    // This line will never be reached
    printf("This will not be printed.\n");

    return 0; // This return statement is also never reached
}

See Also