Destroying Processes
Most processes “die” in the sense that they terminate the execution of the code they were supposed to run. When this occurs, the kernel must be notified so that it can release the resources owned by the process; this includes memory, open files, and any other odds and ends that we will encounter in this book, such as semaphores.
The usual way for a process to terminate is to invoke the
exit( )
library function, which releases the
resources allocated by the C library, executes each function
registered by the programmer, and ends up invoking the
_exit( ) system call. The exit( ) function may be inserted by the programmer explicitly.
Additionally, the C compiler always inserts an exit( ) function call right after the last statement of the
main( ) function.
Alternatively, the kernel may force a process to die. This typically occurs when the process has received a signal that it cannot handle or ignore (see Chapter 10) or when an unrecoverable CPU exception has been raised in Kernel Mode while the kernel was running on behalf of the process (see Chapter 4).
Process Termination
All
process
terminations are handled by the do_exit( )
function, which removes most references to the terminating process
from kernel data structures. The do_exit( )
function executes the following actions:
Sets the
PF_EXITINGflag in theflagfield of the process descriptor to indicate that the process is being eliminated.Removes, if necessary, the process descriptor from an IPC semaphore ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access