接受处理killall信号
#include
#include
#include
void sigroutine(int dunno) { /* 信号处理例程,其中dunno将会得到信号的值 */
switch (dunno) {
case 1:
printf("Get a signal -- SIGHUP \n");
break;
case 2:
printf("Get a signal -- SIGINT \n");
break;
case 3:
printf("Get a signal -- SIGQUIT \n");
break;
case 6:
printf("Get a signal -- SIGABRT \n");
break;
case 9:
printf("Get a signal -- SIGKILL \n");
break;
case 15:
printf("Get a signal -- SIGTERM \n");
signal(SIGTERM, SIG_DFL);
break;
}
return;
}
int main()
{
printf("process id is %d ",getpid());
signal(SIGHUP, sigroutine); //* 下面设置三个信号的处理方法
signal(SIGINT, sigroutine);
signal(SIGQUIT, sigroutine);
signal(SIGABRT, sigroutine);
signal(SIGKILL, sigroutine);
signal(SIGTERM, sigroutine);
for (;;)
sleep(10);
}
阅读(2151) | 评论(0) | 转发(0) |