#include "signal.h" #include // now #include // pause #include // strsignal #include // cout endl int counter = 3; void handler(int s) { auto now = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::to_time_t(now); std::cout << strsignal(s) << " --> " << std::ctime(&time) << std::flush; --counter; } int main() { try { as::signal s(SIGINT, handler); std::cout << "Press Ctrl+C to trigger the signal handler... (x" << counter << " to exit)\n"; while (counter > 0) pause(); } catch (const std::system_error &e) { std::cerr << "Error installing signal handler: " << e.what() << '\n'; return 1; } return 0; }