pending.c

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

C
38
字号
/* * pending.c - Fun with sigpending */#include <unistd.h>#include <signal.h>#include <stdio.h>#include <stdlib.h>int main(void){     sigset_t set, pendset;     struct sigaction action;     sigemptyset(&set);     /* Add the interesting signal */     sigaddset(&set, SIGTERM);     /* Block the signal */     sigprocmask(SIG_BLOCK, &set, NULL);	     /* Send SIGTERM to myself */     kill(getpid(), SIGTERM);     /* Get pending signals */     sigpending(&pendset);     /* If SIGTERM pending, ignore it */     if(sigismember(&pendset, SIGTERM)) {    	  sigemptyset(&action.sa_mask);	  action.sa_handler = SIG_IGN; /* Ignore SIGTERM */	  sigaction(SIGTERM, &action, NULL);     }          /* Unblock SIGTERM */     sigprocmask(SIG_UNBLOCK, &set, NULL);          exit(EXIT_SUCCESS);}

⌨️ 快捷键说明

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