linux实验——信号

linux实验——信号_第1张图片

linux实验——信号_第2张图片 

linux实验——信号_第3张图片 

#include
#include
#include
#include
void handler(int sig);
int main()
{
	sigset_t sigignore;
	sigemptyset(&sigignore);
	sigaddset(&sigignore,SIGINT);
	struct sigaction act;
	act.sa_handler=handler;
	sigemptyset(&act.sa_mask);
	act.sa_flags=0;
	sigaction(SIGINT,&act,0);
	sigaction(SIGQUIT,&act,0);
	printf("Please input a signal\n");
	pause();
	pause();
	printf("Please input a signal\n");
	sigprocmask(SIG_SETMASK,&sigignore,0);
	pause();
	sigdelset(&sigignore,SIGINT);
	sigprocmask(SIG_SETMASK,&sigignore,0);
	printf("ignaorance has been canceled\n");
	printf("Please input a signal\n");
	pause();
}
void handler(int sig)
{
	if(sig == SIGINT){
		printf("I have get SIGINT\n");
	}
	else if(sig == SIGQUIT){
		printf("I have get SIGQUIT\n");
	}
}

 

 

 

你可能感兴趣的:(linux,ubuntu)