1,接受信号
void handler(int num){
printf("recv num%d\n",num);
}
int main(void){
int n =10;
printf("main ....begin\n");
signal(SIGINT,handler);
do{
n=sleep(n);
}while(n>0);
printf("sleep...结束\n");
return 0;
}
1,sigaction 带返回值的信号处理函数
void handler(int sig){
if(sig == SIGINT){
printf("recv a sig=%d\n",sig);
printf("\n\n\n");
}else if(sig == SIGQUIT){
sigset_t uset;
sigemptyset(&uset);
sigaddset(&uset,SIGINT);
sigprocmask(SIG_UNBLOCK,&uset,NULL);
}}
int main(int argc,char *argv[]){
struct sigaction act;
struct sigaction
act.sa_handler = handler;
sigaction(SIGINT,&act,NULL);
for(;;){
//printsigset(&pset);
sleep(1);
}return 0;}