C/C++single
#include <iostream>
#include <unistd.h>
#include <csignal>
#include <string.h>
using namespace std;
void signal_handler(int signal)
{
cout << "Caught signal number " << std::to_string(signal) << " (" << strsignal(signal) << ")" << endl;
if ((signal == SIGABRT) || (signal == SIGTERM) || (signal == SIGINT)) {
cout << "Example program exit." << endl;
exit(0);
}
}
int main()
{
cout << "Example application started" << endl;
// Set signal handlers
std::signal(SIGABRT, &signal_handler);
std::signal(SIGTERM, &signal_handler);
std::signal(SIGINT, &signal_handler);
// loop
for (;;) {
cout << "for -----" << endl;
pause();
}
return 0;
}