接受处理killall信号
时间:2010-10-21 来源:xuxiyao8888
接受处理killall信号
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
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);
}
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
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);
}
相关阅读 更多 +