- 论坛徽章:
- 0
|
static bool sigReceived = false;
struct sigaction tSigAct;
void sigCloseHandler (int signo, siginfo_t*, void *)
{
switch (signo)
{
case SIGINT :
{
sigReceived = true;
cout<<"Received SIGINT signal\n"<<endl;
break;
}
case SIGQUIT :
{
cout<<"Received SIGQUIT signal\n"<<endl; break;
}
case SIGABRT :
{
break;
}
case SIGPIPE :
{
sigReceived = true;
sigReceivedValue = SIGPIPE;
cout<<"Received SIGABRT signal\n"<<endl;
break;
}
case SIGTERM :
sigReceived = true;
cout<<"Received SIGTERM signal\n"<<endl;
break;
}
case SIGUSR1 :
{
cout<<"Received SIGUSR1 signal\n"<<endl;
break;
}
}
}
tSigAct.sa_handler = (void(*)(int)) sigCloseHandler;
sigemptyset( &tSigAct.sa_mask );
tSigAct.sa_flags = 0;
if ( sigaction( SIGINT, &tSigAct, (struct sigaction *) NULL ) == -1 )
{ cout < <"Unable to trap SIGINT signal due to error %d\n" < <endl; }
if ( sigaction( SIGQUIT, &tSigAct, (struct sigaction *) NULL ) == -1 )
{ cout < <"Unable to trap SIGQUIT signal due to error %d\n" < <endl;}
if ( sigaction( SIGABRT, &tSigAct, (struct sigaction *) NULL ) == -1 )
{ cout < <"Unable to trap SIGABRT signal due to error %d\n" < <endl;;}
if ( sigaction( SIGTERM, &tSigAct, (struct sigaction *) NULL ) == -1 )
{ cout < <"Unable to trap SIGTERM signal due to error %d\n" < <endl;}
if ( sigaction( SIGUSR1, &tSigAct, (struct sigaction *) NULL ) == -1 )
{ cout < < "Unable to trap SIGUSR1 signal due to error %d\n" < <endl;}
while ( ! sigReceived ){...}
cout<< sigReceived<<endl;
当sigReceived为true时候,没有看到任何的信号log的信息。这是什么原因呢? |
|