Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
关于一个信号处理的问题
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index 中文 (Chinese)
View previous topic :: View next topic  
Author Message
struggleforgentoo
n00b
n00b


Joined: 07 Jun 2011
Posts: 14

PostPosted: Tue Sep 20, 2011 2:33 pm    Post subject: 关于一个信号处理的问题 Reply with quote

#include "apue.h"
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>

static jmp_buf env_alrm;

void
sig_alrm(int signo)
{
longjmp(env_alrm, 1);
}

unsigned int
sleep2(unsigned int nsecs)
{
if (signal(SIGALRM, sig_alrm) == SIG_ERR)
err_sys("sig_alrm error");
if (setjmp(env_alrm) == 0)
{
alarm(nsecs);
pause();
}
return(alarm(0));
}

static void
sig_int(int signo)
{
int i, j;

volatile int k;

printf("\nsig_int starting\n");
for (i = 0; i < 3000000; i++)
for (j = 0; j < 300000; i ++)
k = i + j;
printf("sig_int finished\n");
}

int
main(void)
{
unsigned int unslept;

if (signal(SIGINT, sig_int) == SIG_ERR)
err_sys("signal error");
unslept = sleep2(10);
printf("sleep2 returned: %u\n", unslept);
exit(0);

}


我的问题是:
为什么我的这个程序不能处理两次中断,第一次中断能处理,第二次中断不能处理
_________________
做自己喜欢做的事是一种快乐
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index 中文 (Chinese) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum