Chinaunix首页 | 论坛 | 博客
  • 博客访问: 42705
  • 博文数量: 9
  • 博客积分: 1617
  • 博客等级: 上尉
  • 技术积分: 85
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-21 00:56
文章分类
文章存档

2010年(9)

分类: C/C++

2010-09-21 23:51:19

在apue里fig10.30这个例子,我一下子想不通下面这句话啥意思:

if (signal(SIGTSTP, SIG_ING) == SIG_DFL)
        signal(SIGTSTP, sig_tstp);


为什么?为什么if的判断条件是那句话?
呵呵,其实英文原版的书是这么说的:
When the program in starts, it arranges to catch the SIGTSTP signal only if the signal's disposition is SIG_DFL. The reason is that when the program is started by a shell that doesn't support job control (/bin/sh, for example), the signal's disposition should be set to SIG_IGN.
意思是:
只有当进程设置的SIGTSTP的处理方式为SIG_DFL时,才捕捉信号;因为不支持作业控制的程序对于此信号的设置是SIG_IGN,所以我们捕捉最初为SIG_DFL的方式的信号,让它触发sig_tstp信号处理函数。(signal函数返回的是设置之前的进程对信号SIGTSTP的处理方式)。
阅读(1115) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~