exit event loop and terminate process gracefully on receiving signals SIGINT and SIGTERM