#include <iostream>
#include <unistd.h>
#include <signal.h>
using namespace std;
int count = 0;
void catchSig(int signum)
{
//cout<< "进程捕捉到了一个信号,正在处理中: "<< signum << " pid: " << getpid() <<endl;
cout << "final cout :" << count << endl;
}
//typedef void (*catchSig) (int);
int main(int argc,char* argv[])
{
alarm(1);
signal(SIGALRM,catchSig);
while(true) count++;
}
运行结果: