亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 3528 | 回復(fù): 2
打印 上一主題 下一主題

[Linux] 為什么SIGALRM信號(hào)捕捉不到了 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2012-08-21 21:52 |只看該作者 |倒序?yàn)g覽
最近在學(xué)習(xí)linux信號(hào)時(shí)遇到一點(diǎn)問題,百思不得其解,其代碼如下:
  1. #include<setjmp.h>                                                         
  2.   2 #include "../include/apue.h"
  3.   3
  4.   4 static void sig_alrm(int);
  5.   5 static jmp_buf env_alrm;
  6.   6
  7.   7 int main(void)
  8.   8 {
  9.   9     int n;
  10. 10     char line[MAXLINE];
  11. 11
  12. 12     if(signal(SIGALRM, sig_alrm) == SIG_ERR)
  13. 13     {
  14. 14         err_sys("signal error");
  15. 15     }
  16. 16     if(setjmp(env_alrm) != 0)
  17. 17         ;
  18. 18     //  err_quit("set_jmp error");
  19. 19     alarm(10);
  20. 20     printf("read start\n");
  21. 21     if((n = read(STDIN_FILENO, line,MAXLINE)) < 0)
  22. 22         err_sys("read error");
  23. alarm(0);
  24. 24     write(STDOUT_FILENO, line, n);
  25. 25     exit(0);
  26. 26 }
  27. 27
  28. 28 static void sig_alrm(int signo)
  29. 29 {
  30. 30     signal(SIGALRM,sig_alrm);
  31. 31     printf("signal start\n");;
  32. 32     //write(STDOUT_FILENO, line, n);
  33. 33     longjmp(env_alrm,1);
  34. 34 }   
復(fù)制代碼
其運(yùn)行的結(jié)果如下:
  1. [root@localhost signal]# gcc -o lread lread.c ../include/err.c
  2. [root@localhost signal]# ./lread
  3. read start
  4. signal start
  5. read start
復(fù)制代碼
會(huì)捕捉到第一個(gè)定時(shí)信號(hào),但是為什么跳轉(zhuǎn)回去的時(shí)候?qū)IGALRM的信號(hào)就不處理了呢?望懂的童鞋指點(diǎn)一下,萬分感激

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2012-08-22 00:08 |只看該作者
打印下信號(hào)屏蔽子看看吧~~  

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2012-08-22 00:10 |只看該作者
  1. man signal
復(fù)制代碼

In the original Unix systems, when a handler that was established using
       signal()  was  invoked  by the delivery of a signal, the disposition of
       the signal would be reset to SIG_DFL, and  the  system  did  not  block
       delivery  of  further  instances of the signal.  System V also provides
       these semantics for signal().  This was bad because the signal might be
       delivered  again before the handler had a chance to reestablish itself.
       Furthermore, rapid deliveries of the same signal could result in recur‐
       sive invocations of the handler.

The situation on Linux is as follows:

       * The kernel's signal() system call provides System V semantics.
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP