Terminating a Process

A process can be terminated in four ways:

  • The primary thread’s entry-point function returns. (This is highly recommended.)

  • One thread in the process calls the ExitProcess function. (Avoid this method.)

  • A thread in another process calls the TerminateProcess function. (Avoid this method.)

  • All the threads in the process just die on their own. (This hardly ever happens.)

This section discusses all four methods and describes what actually happens when a process ends.

The Primary Thread’s Entry-Point Function Returns

You should always design an application so that its process terminates only when your primary thread’s entry-point function returns. This is the only way to guarantee that all your primary thread’s resources are cleaned up ...

Get Windows® via C/C++, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.