> For the complete documentation index, see [llms.txt](https://106-sam.gitbook.io/ejptv2-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://106-sam.gitbook.io/ejptv2-notes/crto/malware-essentials/processes/termination.md).

# Termination

A process may terminate itself gracefully by calling [ExitProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-exitprocess). This is generally linked into every executable by the compiler and called when the program's primary thread returns from the main function. However, a programmer may also call it explicitly if they wish. When a process is terminated 'gracefully', it means that other modules loaded into the process (e.g. DLLs) are given a chance to do some work before the process's resources are disposed of. ExitProcess can only be used by a program to terminate itself.

A process may terminate another process by calling [TerminateProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminateprocess). However, this forces an 'ungraceful' termination, which means all the process's threads are terminated abruptly and loaded modules are not given a chance to do any work before hand. Therefore, this can result in data loss or corruption, depending on what the process is doing when terminated.
