Handling panic, errors, and signals
Processes can fail due to various error conditions. These have to be handled in a controlled manner. There may also be situations where we want to terminate a process in response to external inputs, such as a user pressing Ctrl + C. How we can handle such situations is the focus of this section.
Note
In cases when processes exit due to errors, the operating system itself performs some cleanup, such as releasing memory, closing network connections, and releasing any file handles associated with the process. But sometimes, you may want program-driven controls to handle these cases.
Failures in process execution can broadly be classified into two types – unrecoverable errors and recoverable errors. When a process encounters an unrecoverable error, there is sometimes no option but to abort the process. Let's see how to do that.
Aborting the current process
We saw how to terminate and exit from a process in the Spawning processes...