⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig10.24

📁 Unix Advanced Programming Source Code Unix1-7
💻 24
字号:
#include "apue.h"static volatile sig_atomic_t sigflag; /* set nonzero by sig handler */static sigset_t newmask, oldmask, zeromask;static voidsig_usr(int signo)	/* one signal handler for SIGUSR1 and SIGUSR2 */{	sigflag = 1;}voidTELL_WAIT(void){	if (signal(SIGUSR1, sig_usr) == SIG_ERR)		err_sys("signal(SIGUSR1) error");	if (signal(SIGUSR2, sig_usr) == SIG_ERR)		err_sys("signal(SIGUSR2) error");	sigemptyset(&zeromask);	sigemptyset(&newmask);	sigaddset(&newmask, SIGUSR1);	sigaddset(&newmask, SIGUSR2);	/*	 * Block SIGUSR1 and SIGUSR2, and save current signal mask.	 */	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)		err_sys("SIG_BLOCK error");}voidTELL_PARENT(pid_t pid){	kill(pid, SIGUSR2);		/* tell parent we're done */}voidWAIT_PARENT(void){	while (sigflag == 0)		sigsuspend(&zeromask);	/* and wait for parent */	sigflag = 0;	/*	 * Reset signal mask to original value.	 */	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)		err_sys("SIG_SETMASK error");}voidTELL_CHILD(pid_t pid){	kill(pid, SIGUSR1);			/* tell child we're done */}voidWAIT_CHILD(void){	while (sigflag == 0)		sigsuspend(&zeromask);	/* and wait for child */	sigflag = 0;	/*	 * Reset signal mask to original value.	 */	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)		err_sys("SIG_SETMASK error");}

⌨️ 快捷键说明

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