3.2 Including the initial parent process, how many processes are created by the program shown in Figure?

答案: 会创建8个进程。

解析:相关知识: fork函数的执行原理

  fork函数执行一次, 返回两次,父进程返回子进程的PID, 子进程返回0(至于返回值为什么不同, 这与do_fork函数有关,具体是怎么一回事我还不太清楚)。程序中可利用此性质来区别程序的父进程和子进程。

  当一个进程执行fork函数时, 其新建的子进程得到一份父进程用户级虚拟内存空间的拷贝, 包括文本、数据和bbs段、堆和用户栈, 子进程会得到一个和父进程相同的PCB。因为程序在操作系统中运行的时候,程序执行指令是由program counter(程序计数器)来控制的, 因为子进程PCB中的program counter信息和父进程PCB的program counter信息相同, 所以子进程会继续向后执行指令, 而不会执行父进程fork之前的指令。执行如下图显示的程序,fork出来的子进程不会执行fork之前的printf语句。

程序的运行结果:p hello

        p world

  现在来讲解一下3.2题的程序。画进程图。 假设在return 0之前printf一个hello

  当程序运行到第一个fork时, 创建一个子进程c1, 在上面的进程图中, 用垂直的箭头表示父进程创建了一个子进程, 与垂直箭头相连的线代表新建的子进程的进程线。 在子进程c1中, 会继续向下执行剩余的两个fork, 在执行剩余两个fork中的第一个时, 又会创建一个子进程c2, 而子进程c2会继续向下执行剩余的最后一个fork, c2又会创建一个新的子进程c3, c3执行printf, 之后return 0,c3进程结束, c2之后也会执行printf并return 0结束。 图中的进程都是按照程序运行的逻辑画出来的。 所以, 包含最初的父进程在内, 一共有8个进程。

[Chapter 3 Process]Practice 3.2 Including the initial parent process, how many processes are created by the program shown in Figure?的更多相关文章

  1. [Chapter 3 Process]Practice 3.12 Including the initial parent process, how many processes are created by the program shown in Figure 3.32?

    3.12 Including the initial parent process, how many processes are created by the program shown in Fi ...

  2. [Chapter 3 Process]Practice 3.5 When a process creates a new process using the fork() operation

    3.5 When a process creates a new process using the fork() operation, which of the following state is ...

  3. [Chapter 3 Process]Practice 3.3 Discuss three major complications that concurrent processing adds to an operating system.

    3.3  Original version of Apple's mobile iOS operating system provied no means of concurrent processi ...

  4. [Chapter 3 Process]Practice 3.9 Describe the actions token by a kernel to content-switch between processes.

    3.9 Describe the actions token by a kernel to content-switch between processes. 答案: 内核在进行进程上下文切换时, 首 ...

  5. [Chapter 3 Process]Practice 3.8: Describe the differences among short-term, medium-term, long-term scheduling

    3.8 Describe the differences among short-term, medium-term, and longterm scheduling. 答案: 长期调度决定哪些进程进 ...

  6. [Chapter 3 Process]Practice 3.4 Describe what happens when a context switch occurs if the new context is already loaded into one of the register sets.

    3.4 The Sun UltraSPARC processor has multiple register sets. Describe what happens when a context sw ...

  7. [Chapter 3 Process]Practice 3.1 相关知识:进程创建、fork函数

    3.1 Using the program shown in the Figure3.30, explain what the output will be at LINE A 答案:LINE A 处 ...

  8. Linux process authority、the security risks in running process with high authority

    catalog . Linux进程权限原理 . 最小权限原则 - 进程降权运行最佳实践 . 进程权限控制包含的攻防向量 . 进程高权限安全风险检查技术方案 1. Linux进程权限原理 我们知道,Li ...

  9. 查看进程id, 父进程id _How do I get the parent process ID of a given child process?

    How to get parent pid from a given children pid? I know I can mannully check it under /proc, I am wo ...

随机推荐

  1. matplotlib两种画散点图的方式

    对于matplotlib.pyplot( as plt ) 先输入主体数据部分: import numpy as np import matplotlib.pyplot as plt X_train ...

  2. FMX.TTabControl_多行

    1. 重载 TTabControl.RealignTabs; 2. 3.

  3. Mirantis对OpenStack的性能测试:高并发创建75000台虚拟机

    硅谷创业公司Mirantis不久前进行了一项基准测试,测试在OpenStack Havana版本上创建75000台虚拟机的性能数据.就启动时间和成功率而言,当应用250个并发部署75000台虚拟机是最 ...

  4. weinre远程调试

    一: 关于weinre weinre是一款依赖于nodejs的远程调试工具,现阶段一般用到手机app上调试非常的强大 二: weinre的安装 1)  安装 nodejs以及npm 2) 安装wein ...

  5. ​Php加速原理及工具试验

    Php加速原理及工具测试 本实验相关软件地址:http://pan.baidu.com/s/1dDuwvE5 第一部分.Php加速分类: 一.缓冲层级别的优化 1.xCache是把 PHP 操作码缓存 ...

  6. 解决:Eclipse安装Pydev插件报错: An error occurred while collecting items to be installed session context was:(profile=...

    今天在Elipse上安装Pydev插件时报错: An error occurred while collecting items to be installed session context was ...

  7. ZOJ - 3430 ac自动机

    这题主要就是解码过程很恶心,不能用char存,一共wa了20发 题意:先给n串加密后的字符,然后m串加密后的字符,解码之后求n对应每个m的匹配数,很显然的ac自动机 加密过程是先用对应ascii表的标 ...

  8. deep learning 学习笔记(三) 线性回归学习速率优化寻找

    继续学习http://www.cnblogs.com/tornadomeet/archive/2013/03/15/2962116.html,上一节课学习速率是固定的,而这里我们的目的是找到一个比较好 ...

  9. 条款44:将与参数无关的代码剥离template

    使用template时,不小心的时候可能就会带来代码膨胀的问题: template<typename T, std::size_t n> class SquareMatrix{ publi ...

  10. uva12563 Jin Ge Jin Qu hao(01背包)

    这是一道不错的题.首先通过分析,贪心法不可取,可以转化为01背包问题.但是这过程中还要注意,本题中的01背包问题要求背包必须装满!这就需要在普通的01背包问题上改动两处,一个是初始化的问题:把dp[0 ...