当前位置: 技术问答>linux和unix
在linux中无人解答!!linux简单信号问题。
来源: 互联网 发布时间:2016-11-06
本文导语: 下面是一段关于信号的代码,看了过后有点不理解,如果现在sig_audio_enable这个信号函数被执行了,在这个信号函数里面会执行alarm(2);那么经过2微妙后 void sigint(int dummy) 这个信号会被执行,void sigint(int dummy)这个函...
下面是一段关于信号的代码,看了过后有点不理解,如果现在sig_audio_enable这个信号函数被执行了,在这个信号函数里面会执行alarm(2);那么经过2微妙后 void sigint(int dummy) 这个信号会被执行,void sigint(int dummy)这个函数里面调用了alarm(1);也就是在1微妙以后 void sigint(int dummy)这个函数会被执行,如此反复下去,感觉这样执行很奇怪!!!是我理解错误了吗???请高手指教一下啊!!!
void sigterm(int dummy)
{
printf("caught SIGTERM: shutting downn");
ApproInterfaceExit();
exit(1);
}
void sigint(int dummy)
{
if( IsAudioAlarm == 1 )
{
printf("Audio Alarm!!n");
IsAudioAlarm = 0;
return;
}
printf("caught SIGINT: shutting downn");
//printf("watchVariable = %dn",watchVariable);
//printf("videoType = %dn",videoType);
watchVariable = 1;
alarm(1);
//ApproInterfaceExit();
//exit(1);
}
void sig_audio_enable(int dummy)
{
printf("Audio enabled!n");
audio_enable = 1;
//printf("videoType = %dn",videoType);
IsAudioAlarm = 1;
alarm(2);
}
void sig_audio_disable(int dummy)
{
printf("Audio disabled!n");
audio_enable = 0;
//printf("videoType = %dn",videoType);
IsAudioAlarm = 1;
alarm(2);
}
void init_signals(void)
{
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGTERM);
sigaddset(&sa.sa_mask, SIGINT);
sigaddset(&sa.sa_mask, SIGUSR1);
sigaddset(&sa.sa_mask, SIGUSR2);
sigaddset(&sa.sa_mask, SIGALRM);
sa.sa_flags = 0;
sa.sa_handler = sigterm;
sigaction(SIGTERM, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sigint;
sigaction(SIGINT, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sig_audio_enable;
sigaction(SIGUSR1, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sig_audio_disable;
sigaction(SIGUSR2, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sigint;
sigaction( SIGALRM, &sa, NULL );
}
void sigterm(int dummy)
{
printf("caught SIGTERM: shutting downn");
ApproInterfaceExit();
exit(1);
}
void sigint(int dummy)
{
if( IsAudioAlarm == 1 )
{
printf("Audio Alarm!!n");
IsAudioAlarm = 0;
return;
}
printf("caught SIGINT: shutting downn");
//printf("watchVariable = %dn",watchVariable);
//printf("videoType = %dn",videoType);
watchVariable = 1;
alarm(1);
//ApproInterfaceExit();
//exit(1);
}
void sig_audio_enable(int dummy)
{
printf("Audio enabled!n");
audio_enable = 1;
//printf("videoType = %dn",videoType);
IsAudioAlarm = 1;
alarm(2);
}
void sig_audio_disable(int dummy)
{
printf("Audio disabled!n");
audio_enable = 0;
//printf("videoType = %dn",videoType);
IsAudioAlarm = 1;
alarm(2);
}
void init_signals(void)
{
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGTERM);
sigaddset(&sa.sa_mask, SIGINT);
sigaddset(&sa.sa_mask, SIGUSR1);
sigaddset(&sa.sa_mask, SIGUSR2);
sigaddset(&sa.sa_mask, SIGALRM);
sa.sa_flags = 0;
sa.sa_handler = sigterm;
sigaction(SIGTERM, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sigint;
sigaction(SIGINT, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sig_audio_enable;
sigaction(SIGUSR1, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sig_audio_disable;
sigaction(SIGUSR2, &sa, NULL);
sa.sa_flags = 0;
sa.sa_handler = sigint;
sigaction( SIGALRM, &sa, NULL );
}
|
同样不解~~~