#include
#include
#include
#define oops(ch) {perror(ch);return -1;}
static void sig_usr1(int),sig_alrm(int);
static sigjmp_buf jmpbuf;
static volatile sig_atomic_t canjump;
int main()
{
if(signal(SIGUSR1,sig_usr1)==SIG_ERR)
oops("signal at SIGUSR1");
if(signal(SIGALRM,sig_alrm)==SIG_ERR)
oops("signal at SIGALRM");
printf("starting main:\n ");
if(sigsetjmp(jmpbuf,1))
{
printf("ending main:\n");
exit(0);
}
canjump=1;
for(;;)
pause();
}
static void sig_usr1(int signo)
{
time_t starttime;
if(canjump==0)
return ;
printf("starting sig_usr1\n");
alarm(3);
starttime=time(NULL);
for(;;)
{
if(time(NULL)>starttime+5)
break;
}
printf("finishing sig_usr1:\n");
canjump=0;
siglongjmp(jmpbuf,1);
}
static void sig_alrm(int signo)
{
printf("in sig_alrm\n");
}
#cc -g signal3.c -o signal
#gdb signal
(gdb) r
Starting program: /home/program/signal/signal
Breakpoint 1, main () at signal3.c:12
12 {
(gdb) n
main () at signal3.c:13
13 if(signal(SIGUSR1,sig_usr1)==SIG_ERR)
(gdb) n
16 if(signal(SIGALRM,sig_alrm)==SIG_ERR)
(gdb) n
19 printf("starting main:\n ");
(gdb) n
starting main:
20 if(sigsetjmp(jmpbuf,1))
(gdb) n
26 canjump=1;
(gdb) n
29 pause();
(gdb) shell ps
PID TTY TIME CMD
2489 pts/2 00:00:00 bash
2659 pts/2 00:00:00 gdb
2660 pts/2 00:00:00 signal
2663 pts/2 00:00:00 ps
(gdb) shell kill -USR1 2660
(gdb) n
Program received signal SIGUSR1, User defined signal 1.
main () at signal3.c:29
29 pause();
(gdb) n
sig_usr1 (signo=10) at signal3.c:34
34 {
(gdb) n
36 if(canjump==0)
(gdb) n
39 printf("starting sig_usr1\n");
(gdb) n
starting sig_usr1
40 alarm(3);
(gdb) n
41 starttime=time(NULL);
(gdb) n
44 if(time(NULL)>starttime+5)
(gdb) p starttime
$1 = 1270436678
(gdb) n
in sig_alrm
47 printf("finishing sig_usr1:\n");
(gdb) n
finishing sig_usr1:
48 canjump=0;
(gdb) n
49 siglongjmp(jmpbuf,1);
(gdb) n
Warning:
Cannot insert breakpoint -8.
Error accessing memory address 0x800b08e8: 输入/输出错误.
请问最后的的那两行是什么错误?为什么用n(单步执行)的时候没执行跳转后的语句?
谢谢!