#include #include #include using namespace std; static void Handler(int sig); static void Killer(int sig); void SetHandler(int sig, void (*hand)(int) ); int main() { cout << endl; cout << "My process id is " << getpid() << endl; cout << endl; SetHandler(SIGUSR1, Handler); SetHandler(SIGUSR2, Killer); SetHandler(SIGKILL, Handler); while(1) { } return 0; } void SetHandler(int sig, void (*hand)(int) ) { if (SIG_ERR == signal(sig, hand) ) { string error{"Failed to set signal " + to_string(sig) + " : "}; perror(error.c_str()); } } static void Killer(int sig){ cout << "Just got " << sig << endl; cout << "And I will exit." << endl; exit(0); } static void Handler(int sig) { cout << "I just got a signal " << sig << endl; cout << endl; }