【发布时间】:2010-12-12 15:05:12
【问题描述】:
在这种情况下,我写了一个简单的 prog:
int main()
{
pid_t chpid;
chpid=fork();
if(chpid==0) // child
{
sleep(2);
execlp("/usr/bin/man","/usr/bin/man","ps",NULL);
printf("still alive\n");
}
else
{
printf("parent goes down\n");
}
return 0;
}
当正在运行的父母死亡时,我在 2 秒内得到:/usr/bin/man: command exited with status 1: pager -s
为什么会这样运行?绝对问题是父母的死,如果我在父母的代码中添加 while(1) 一切都很好。
我编写了一个测试程序,它会在每个时间段将一些字符串写入标准输出。有用。看起来很奇怪。
【问题讨论】: