【问题标题】:Return statement of child process when forking()forking() 时子进程的返回语句
【发布时间】:2015-06-23 05:20:14
【问题描述】:

Hello 打印了多少行?

int main(){
    fn();
     printf("Hello \n");
    exit(0);
    }

  void fn(){     
    if(fork() == 0){
     fork();
      printf("Hello \n");
    }
    return;
  }

我是这个主题的新手,想了解子进程的行为方式。 我看到上面问题的答案是5。

我知道会打印 3 条语句。

我的问题:

做return语句,将子进程返回给main()函数 因此子进程从那里执行?

【问题讨论】:

    标签: unix process operating-system fork child-process


    【解决方案1】:

    return 语句是否将子进程返回给 main() 函数,从而子进程从那里执行?

    是的,它们会像您的主进程一样继续执行,除非您在子进程中过早地exit()

    【讨论】:

    • 这有帮助。谢谢。
    猜你喜欢
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多