Signal handling
Signal handling allows us to catch signals sent by the OS and gracefully shut down the application before the OS decides to kill the application’s process.
Boost.Asio provides the boost::asio::signal_set
class for this purpose, which starts an asynchronous wait for one or more signals to occur.
This is an example of how to handle the SIGINT
and SIGTERM
signals:
#include <boost/asio.hpp> #include <iostream> int main() { try { boost::asio::io_context io_context; boost::asio::signal_set signals(io_context, SIGINT, SIGTERM); auto handle_signal = [&]( ...