Skip to content

Instantly share code, notes, and snippets.

@kashimAstro kashimAstro/sig.cpp
Created Mar 20, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.