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

📄 test2.c

📁 让你了解Unix进程间的通信是如何实现的
💻 C
字号:
/* * See if signals other than the realtime signals are queued, * and if SA_SIGINFO works with these other signals. */#include	"unpipc.h"static void	sig_rt(int, siginfo_t *, void *);intmain(int argc, char **argv){	int		j;	pid_t	pid;	sigset_t	newset, oldset;	union sigval	val;	if ( (pid = Fork()) == 0) {			/* 4block all signals except SIGALRM */		Sigfillset(&newset);		Sigdelset(&newset, SIGALRM);		Sigprocmask(SIG_SETMASK, &newset, &oldset);			/* establish signal handler with SA_SIGINFO set */		Signal_rt(SIGUSR1, sig_rt);		Signal_rt(SIGTERM, sig_rt);		sleep(6);		/* let parent send all the signals */		Sigprocmask(SIG_SETMASK, &oldset, NULL);	/* unblock */		sleep(3);		/* let all queued signals be delivered */		exit(0);	}	sleep(3);		/* let child block all signals */		/* 4parent sends 12 signals to child */	for (j = 0; j <= 6; j++) {		val.sival_int = j;		Sigqueue(pid, SIGUSR1, val);		printf("sent SIGUSR1 (%d), val = %d\n", SIGUSR1, j);	}	for (j = 0; j <= 6; j++) {		val.sival_int = j;		Sigqueue(pid, SIGTERM, val);		printf("sent SIGTERM (%d), val = %d\n", SIGTERM, j);	}	Waitpid(pid, NULL, 0);		/* wait for child */	exit(0);}static voidsig_rt(int signo, siginfo_t *info, void *context){	printf("received signal #%d, code = %d, ival = %d\n",		   signo, info->si_code, info->si_value.sival_int);}

⌨️ 快捷键说明

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