Skip to content

Instantly share code, notes, and snippets.

@kashimAstro
Created March 20, 2018 10:19
Show Gist options
  • Save kashimAstro/6b5abd6997918d49c606c759de95722b to your computer and use it in GitHub Desktop.
Save kashimAstro/6b5abd6997918d49c606c759de95722b to your computer and use it in GitHub Desktop.
sample sig
#include <signal.h>
#include <iostream>
#include <unistd.h>
// kill -9 pid
// kill -15 pid
// kill pid
// Ctrl+c
using namespace std;
void signalExit(int sig){
if (sig == SIGINT)
cout << "close SIGINT" << endl;
if (sig == SIGTERM)
cout << "close SIGTERM" << endl;
if (sig == SIGKILL)
cout << "close SIGKILL" << endl;
//unexport pin
exit(0);
}
int main()
{
signal(SIGINT, signalExit);
signal(SIGTERM, signalExit);
signal(SIGKILL, signalExit);
while(1){
cout<< "test"<< endl;
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment