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

📄 sigactdemo.c

📁 unix linux 编程实践源代码
💻 C
字号:
/* sigactdemo.c *               purpose: shows use of sigaction() *               feature: blocks ^\ while handling ^C *                        does not reset ^C handler, so two kill */#include	<stdio.h>#include	<signal.h>#define	INPUTLEN	100main(){	struct sigaction newhandler;            /* new settings        */	sigset_t         blocked;               /* set of blocked sigs */	void		 inthandler();          /* the handler         */	char		 x[INPUTLEN];	/* load these two members first */	newhandler.sa_handler = inthandler;      /* handler function    */	newhandler.sa_flags = SA_RESETHAND | SA_RESTART;  /* options    */	/* then build the list of blocked signals */	sigemptyset(&blocked);                  /* clear all bits      */	sigaddset(&blocked, SIGQUIT);		/* add SIGQUIT to list */	newhandler.sa_mask = blocked;		/* store blockmask     */	if ( sigaction(SIGINT, &newhandler, NULL) == -1 )		perror("sigaction");	else		while( 1 ){			fgets(x, INPUTLEN, stdin);			printf("input: %s", x);		}}void inthandler(int s){	printf("Called with signal %d\n", s);	sleep(s);	printf("done handling signal %d\n", s);}

⌨️ 快捷键说明

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