April 2020
Intermediate to advanced
412 pages
9h 58m
English
We need a mechanism to terminate our application when it hangs. Though we could spawn a special monitoring thread or process, there is another, simpler way to do this—POSIX signals.
Any process running in a POSIX operating system can receive a number of signals. To deliver a signal to the process, the operating system stops the normal execution of the process and invokes a corresponding signal handler.
One of the signals that can be delivered to the process is called alarm and, by default, its handler just terminates the application. This is exactly what we need to implement a watchdog.
The constructor of our Watchdog class accepts one parameter, seconds:
Watchdog(std::chrono::seconds seconds):
It is a time interval for ...
Read now
Unlock full access