whutxuan
驱动小牛
驱动小牛
  • 注册日期2002-03-05
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望1点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
阅读:847回复:3

父子进程的问题!!!

楼主#
更多 发布于:2003-03-22 16:55
void process(void)
{
    pid_t pid;
    pid=fork();
    if(pid<0)
    {
        perror(\"fork failed\\n\");
    }
    if(pid>0)
     {
           return;//不用exit(0);是因为想回到main中去处理printf(\"hello world\\n\")!就不会打印hello world了。
      }
      else
      {
           sleep(100);
           exit(0);//如果用return则,会提示unexpect reply from(0x38);的提示,请问为什么呢?
      }
}


int main(void)
{
   process();
   printf(\"hello world\\n\")!
   return 1;
}
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-03-24 08:56
不太可能出现这个问题。 不过子进程会成为ZOMBIE, 而且这个问题的出现不是内核的问题。
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
heehaw
驱动小牛
驱动小牛
  • 注册日期2003-03-20
  • 最后登录2005-04-25
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-03-24 09:02
在子进程开始执行时,父进程应该已经结束了吧。
所以子进程再return的话,可能就不对了。
我也不知道对不对,乱说的 :P :P :P
我热爱生命,但面对现实的社会经常感到无奈,所以只有嘿嘿傻笑 我迷恋科技,但飞速发展的世界使我眼花缭乱,所以必须埋头苦练
heehaw
驱动小牛
驱动小牛
  • 注册日期2003-03-20
  • 最后登录2005-04-25
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-03-24 09:09
我刚试了一下,用return也是可以的,子进程成为ZOMBIE后,会被1号(好像是吧)进程回收的。
好像没有出现你说的问题。 :cool: :cool: :cool:
我热爱生命,但面对现实的社会经常感到无奈,所以只有嘿嘿傻笑 我迷恋科技,但飞速发展的世界使我眼花缭乱,所以必须埋头苦练
游客

返回顶部