#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
using namespace std;
void sig_handler(int signum)
{
if(0 > signum)
{
fprintf(stderr,"sig_handler param err. [%d]\n",signum);
return;
}
if(SIGINT == signum)
{
printf("Received signal [%s]\n",SIGINTsignum?"SIGINT":"Other");
}
if(SIGQUIT == signum)
{
printf("Received signal [%s]\n",SIGQUITsignum?"SIGQUIT":"Other");
}
return;
}
int main(int argc,char **argv)
{
printf("Wait for the signal to arrive.\n ");
/*登记信息*/
signal(SIGINT,sig_handler);
signal(SIGQUIT,sig_handler);
pause();
pause();
signal(SIGINT,SIG_IGN);
return 0;
}
标签:include,signal,SIGINT,handler,sig,signum,dms
From: https://www.cnblogs.com/yu15141310373/p/16875393.html