- #include<signal.h>
-
-
#include<iostream>
-
-
using namespace std;
-
-
-
-
int alarm_fired;
-
-
-
-
void ding(int sig)
-
-
{
-
-
alarm_fired=1;
-
-
}
-
-
-
-
int main()
-
-
{
-
-
pid_t pid;
-
-
cout<<"alarm application start"<<endl;
-
-
pid=fork();
-
-
if(pid==-1)
-
-
{
-
-
cout<<"error"<<endl;
-
-
exit(1);
-
-
}
-
-
else if(pid==0)
-
-
{
-
-
sleep(5);
-
-
kill(getppid(),SIGALRM);
-
-
exit(0);
-
-
}
-
-
cout<<"wait for alarm to go off"<<endl;
-
-
(void) signal(SIGALRM,ding);
-
-
pause();
-
-
if(alarm_fired)
-
-
cout<<"ding"<<endl;
-
-
cout<<"done"<<endl;
-
-
exit(0);
-
-
}
output:
[xq@m1 ~]$ g++ -o signa_kill signa_kill.cpp
[xq@m1 ~]$ ./signa_kill
alarm application start
wait for alarm to go off
ding
done
[xq@m1 ~]$
阅读(626) | 评论(0) | 转发(0) |