fig10.22

来自「unix环境编程」· 22 代码 · 共 57 行

22
57
字号
#include "apue.h"static void	sig_int(int);intmain(void){	sigset_t	newmask, oldmask, waitmask;	pr_mask("program start: ");	if (signal(SIGINT, sig_int) == SIG_ERR)		err_sys("signal(SIGINT) error");	sigemptyset(&waitmask);	sigaddset(&waitmask, SIGUSR1);	sigemptyset(&newmask);	sigaddset(&newmask, SIGINT);	/*	 * Block SIGINT and save current signal mask.	 */	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)		err_sys("SIG_BLOCK error");	/*	 * Critical region of code.	 */	pr_mask("in critical region: ");	/*	 * Pause, allowing all signals except SIGUSR1.	 */	if (sigsuspend(&waitmask) != -1)		err_sys("sigsuspend error");	pr_mask("after return from sigsuspend: ");	/*	 * Reset signal mask which unblocks SIGINT.	 */	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)		err_sys("SIG_SETMASK error");	/*	 * And continue processing ...	 */	pr_mask("program exit: ");	exit(0);}static voidsig_int(int signo){	pr_mask("\nin sig_int: ");}

⌨️ 快捷键说明

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