#include <signal.h>
#include <unistd.h>
#include <stdio.h>
void sigroutine(int dunno)
{
/*信号处理例程,其中dunno将会得到信号的值 */
switch (dunno) {
case 1:
printf("Get a signal -- SIGHUP \r\n");
break;
case 2:
printf("Get a signal -- SIGINT \r\n");
break;
case 3:
printf("Get a signal -- SIGQUIT \r\n");
break;
}
return;
}
int main()
{
printf("process id is %d \r\n",getpid());
signal(SIGHUP, sigroutine); //* 下面设置三个信号的处理方法
signal(SIGINT, sigroutine);
signal(SIGQUIT, sigroutine);
for (;;) ;
}
/*
# /sb3000t/enroll/sig_demo &
933
# process id is 933
# kill -2 933
# Get a signal -- SIGINT
# Get a signal -- SIGINT
# kill -1 933
# Get a signal -- SIGHUP
#
# kill -3 933
# Get a signal -- SIGQUIT
*/