A process can terminate in one of the following basic ways:
- by exiting (i.e., the process terminates itself)
- by being signalled
- by having no running threads (i.e., the thread count goes to 0 )
In some operating systems, if a parent process dies, then all of its child processes die too.
When a process terminates—no matter why—all of its resources are cleaned up:
- Any remaining threads are terminated.
- All file descriptors are closed.
- All channels and side-channel connections are destroyed.
- All memory mappings for the process are unmapped. This includes code, data, heap, hardware mappings, and shared memory.