Skip to content

Instantly share code, notes, and snippets.

@tomas-rampas
Last active July 27, 2021 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomas-rampas/f96b3efc88da1f622d6426e14697dfdc to your computer and use it in GitHub Desktop.
Save tomas-rampas/f96b3efc88da1f622d6426e14697dfdc to your computer and use it in GitHub Desktop.
#include <iostream>
#include <csignal>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
using namespace std;
void signalHandler( int signum ) {
cout << "Interrupt signal (" << signum << ") received.\n";
// cleanup and close up stuff here
// terminate program
exit(signum);
}
int main () {
// register signal SIGINT and signal handler
signal(SIGINT, signalHandler);
while(1) {
cout << "Going to sleep...." << endl;
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment