免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1523 | 回复: 1
打印 上一主题 下一主题

[C] APUE 10.18的一个问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-22 12:46 |只看该作者 |倒序浏览
APUE第二版 10.18第一个示例程序

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

#include <signal.h>

#include <errno.h>

static void sig_int(int signo);
static void sig_chld(int signo);

int main()
{
    if(signal(SIGINT,sig_int) == SIG_ERR)
    {
        perror("signal SIGINT");
        exit(1);
    }
    if(signal(SIGCHLD,sig_chld) == SIG_ERR)
    {
        perror("signal SIGCHLD");
        exit(1);
    }
    system("/bin/ed");
    exit(0);
}
static void sig_int(int signo)
{
    printf("Caught SIGINT");
}
static void sig_chld(int signo)
{
    printf("Caught SIGCHLD");
}

按照书上所说的,程序运行,进入system调用的ed后,按Ctrl+C,编译后的a.out、system所fork的sh,sh所fork的ed都会收到SIGINT,所以屏幕会显示
"Caught SIGINT",但是我运行程序的结果却不是这样,按Ctrl+C,没有任何显示。难道我哪里搞错了?

论坛徽章:
0
2 [报告]
发表于 2008-09-22 15:03 |只看该作者
缓冲区没有刷新吧?我猜的- -!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP