i*****f 发帖数: 578 | 1 最近在看gnu libc的manual,里面讲到signal handler的时候有这个例子(chapter 24
.4.2, http://www.gnu.org/software/libc/manual/html_node/Termination-in-Handler.html#Termination-in-Handler):
1 volatile sig_atomic_t fatal_error_in_progress = 0;
2
3 void
4 fatal_error_signal (int sig)
5 {
6 /* Since this handler is established for more than one kind of signal,
7 it might still get invoked recursively by delivery of some other
kind
8 of signal. Use a static variable to keep track of that. */
9 if (fatal_err |
p*****s 发帖数: 344 | |
i*****f 发帖数: 578 | 3 但是第10行raise之后,程序会接着往下执行吧?
raise(sig)会给自己一个signal,然后呢?然后程序会接着执行吧?
志。
【在 p*****s 的大作中提到】 : 你可以把这个程序想像成中断调用,为了避免程序本身执行到一半又被调用,加了标志。 : http://en.wikipedia.org/wiki/Reentrant_(subroutine)
|
p*****s 发帖数: 344 | 4 那要看libc raise怎么处理了,看介绍一般raise的用途是调用缺省处理方法,就是把
自己解决了。
程序没有机会往下走了。
【在 i*****f 的大作中提到】 : 但是第10行raise之后,程序会接着往下执行吧? : raise(sig)会给自己一个signal,然后呢?然后程序会接着执行吧? : : 志。
|
i*****f 发帖数: 578 | 5 raise() just send a signal to itself. I think the codes below raise() will
continue to be executed. See man 3 raise. Also, try the following code:
#include
#include
#include
/* A handler for the ALARM signal */
void act_sigalrm(int sig)
{
puts("catched a SIGALRM");
/* raise this signal again. */
raise(sig);
puts("this code will be executed.");
}
int main()
{
signal(SIGALRM, act_sigalrm);
/* issue SIGALRM 3 sec later */
alarm(3);
/* entering event l
【在 p*****s 的大作中提到】 : 那要看libc raise怎么处理了,看介绍一般raise的用途是调用缺省处理方法,就是把 : 自己解决了。 : 程序没有机会往下走了。
|
p*****s 发帖数: 344 | 6 you are right, the code in line 10 doesn't make sense.
I understand the intention is to avoid double fault handling, but to
resend signal to itself can not prevent this.
btw, I take a look at the glibc code, rasie(...) is implemented as one
line kill(...)
will
【在 i*****f 的大作中提到】 : raise() just send a signal to itself. I think the codes below raise() will : continue to be executed. See man 3 raise. Also, try the following code: : #include : #include : #include : /* A handler for the ALARM signal */ : void act_sigalrm(int sig) : { : puts("catched a SIGALRM"); : /* raise this signal again. */
|
i*****f 发帖数: 578 | 7 握手握手~~~
不过还是不明白,我觉得libc的manual应该是很严谨的阿。还是说我不该太take it
serious @.@
【在 p*****s 的大作中提到】 : you are right, the code in line 10 doesn't make sense. : I understand the intention is to avoid double fault handling, but to : resend signal to itself can not prevent this. : btw, I take a look at the glibc code, rasie(...) is implemented as one : line kill(...) : : will
|
p*****s 发帖数: 344 | 8 可以找个真的gnu terminal 程序看看是怎么处理异常的
【在 i*****f 的大作中提到】 : 握手握手~~~ : 不过还是不明白,我觉得libc的manual应该是很严谨的阿。还是说我不该太take it : serious @.@
|