代码:
#include <iostream>
#include <unistd.h>
#include <signal.h>
using namespace std;
void handler (int signum)
{
cout << "获取了一个信号:" << signum << endl;
}
int main()
{
struct sigaction act, oact;
act.sa_flags = 0;
sigemptyset (&act.sa_mask);
act.sa_handler = handler;
sigaction(2,&act,&oact);
cout << "default action : " << (int)oact.sa_handler << endl;
while(true) sleep(1);
return 0;
}
运行结果: