Exercise: Graceful Termination Via SIGTERM/SIGINT#

Our database application still does not commit the database when terminated like processes are usually terminated,

../../../../../../../_images/eventloop-idea.svg
  • Ctrl-C from the terminal, when run in foreground (SIGINT is delivered)

  • kill <PID> from another process; the shell, usually (SIGTERM is delivered)

Add to the application another InputHandler implementation (lets give it the name GracefulTerminator). That implementation uses a signalfd instance to request SIGINT and SIGTERM delivery via a file descriptor.

Add a method GracefulTerminator::hookup(Eventloop&) which does everything that is necessary to make the event loop aware of the file descriptor. See class StdinToDatabase and class UDPToDatabase for how such a hookup() method is usually implemented