原文链接:http://hi.baidu.com/l1l1888/blog/item/9024a2fe75c604305d6008d3.html
用户按下ctrl+c时,进程被中断,catch()被执行.中断处理函数处理完毕
[root@localhost 001]# cat sigint_demo.cpp
#include<iostream>
#include<signal.h>
#include<unistd.h>
using namespace std;
static void catch_(int)
{
cout<<"catch signal!"<<endl;
}
int main(void)
{
int i ;
signal(SIGINT,catch_);
cout<<"hello!"<<endl;
sleep(10);
cout<<"hello!"<<endl;
return 0;
}
[root@localhost 001]# g++ sigint_demo.cpp -o sigint_demo
[root@localhost 001]# ./sigint_demo
hello!
catch signal!
hello!
[root@localhost 001]#