代码:
#include <iostream>
#include <signal.h>
#include <unistd.h>using namespace std;void catchSig(int signum)
{cout<< "进程捕捉到了一个信号,正在处理中: "<< signum << " pid: " << getpid() <<endl;
}//typedef void (*catchSig) (int);int main()
{while(true){cout<< "我是一个进程,我正在运行..., Pid: " << getpid() <<endl;sleep(1);int a = 100;a /= 0;cout << "run here ...." << endl;}
}
Makefile:
signal:signal.ccg++ -o signal signal.cc -g.PHONY:clean
clean:rm -f signal
运行结果: