block.c

来自「基于网络编程的例子」· C语言 代码 · 共 39 行

C
39
字号
/* * block.c - Blocking signals */#include <unistd.h>#include <signal.h>#include <stdlib.h>#include <stdio.h>void err_quit(char *);int main(void){     sigset_t newset;     /* Create the set */     if((sigemptyset(&newset)) < 0)	  err_quit("sigemptyset");     /* Adding SIGTERM and SIGALRM */     if((sigaddset(&newset, SIGTERM)) < 0)	  err_quit("sigaddset:SIGTERM");     if((sigaddset(&newset, SIGALRM)) < 0)	  err_quit("sigaddset:SIGALRM");          /* Block the signals without handling them */     if((sigprocmask(SIG_BLOCK, &newset, NULL)) < 0)	  err_quit("sigprocmask");     /* Wait for a signal */     pause();          exit(EXIT_SUCCESS);}     void err_quit(char *msg){     perror(msg);     exit(EXIT_FAILURE);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?