Exercise: Graceful Termination Via SIGTERM/SIGINT#
Our database application still does not commit the database when terminated like processes are usually terminated,
Ctrl-Cfrom the terminal, when run in foreground (SIGINTis delivered)kill <PID>from another process; the shell, usually (SIGTERMis 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