Last active
July 27, 2021 18:36
-
-
Save tomas-rampas/f96b3efc88da1f622d6426e14697dfdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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