简体   繁体   English

Unix fork:创建了多少个进程?

[英]Unix fork: how many processes are created?

Hi I am doing exercises on Operating System Concepts 9th Edition Chapter 3, there is a "how many processes are created including the parent process?" 嗨,我正在练习操作系统概念第9版第3章,有一个“创建了多少个进程,包括父进程?” question confusing me. 问题令我困惑。 The code is in C with Unix system call, fork(): 代码在C中使用Unix系统调用,fork():

#include <stdio.h>
#include <unistd.h>

int main(){

fork();
fork();
fork();

return 0;
}

How any buddy answer the question? 有什么好友回答这个问题? Thanks 谢谢

fork(); 

1st fork created new process from running process(main) . 1st fork从运行进程(main)创建了新进程。 in System now there is two process 在System现在有两个过程

fork();

Each of Both process again calls fork. 两个进程中的每一个都再次调用fork。 So two new process created. 因此创建了两个新流程。 So total four process is in system now 所以现在共有四个过程在系统中

fork();

Now Each four process calls fork. 现在每四个进程调用fork。 so again four new process created. 所以再创造了四个新流程。 so total eight process is created after last call of fork(); 所以在最后一次调用fork()之后创建了总共八个进程;

我猜它是8,像1 - > 2 - > 4 - > 8

There are total 8 process including parent process. 共有8个过程,包括父过程。 Here, 这里, 使用fork()的进程数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM