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. java基础10(IO流)-字节流

    IO流 输入与输出[参照物是程序] 如果从键盘.文件.网络甚至是另一个进程(程序或系统)将数据读入到程序或系统中,称为输入 如果是将程序或系统中的数据写到屏幕.硬件上的文件.网络上的另一端或者是一个进 ...

  2. HDU 4348 To the moon (主席树区间更新)

    题意:首先给你n个数,开始时间为0,最后按照操作输出 给你四种操作: 1. C l r d :  在(l,r)区间都加上d,时间加一2. Q l r :  询问现在(l,r)的区间和3. H l r ...

  3. 关于series的统计

    1.统计se中各个元素出现的次数: se.value_counts() 这个命令就非常重要!(df没有这个命令) 另外series转dict是to_dict(),注意与数组转list的tolist() ...

  4. 算法练习1---桶排序java版

    今天复习了桶排序. 例如现在有满分为10分的试卷,学生得分分别为2,8,5,3,5,7,现在要给这些分数按照从大到小输出,使用桶排序的思想:有11个桶,每个桶有一个编号,编号从0-10,每出现一个分数 ...

  5. LeetCode OJ:Same Tree(相同的树)

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  6. hdoj-1038-Biker's Trip Odometer(水题)

    题目真的考验英语 题目链接 需要进行单位的转换 对于Pi用:3.1415927. 5280步相当于1英里. 12英寸相当于1步. 60分钟等于1小时 60秒等于1分钟. 201.168米等于1弗朗.( ...

  7. IP地址的基础划分

    1.基础知识 1.1  IP地址是由网络号(net ID)与主机号(host ID)两部分组成的. 1.2  IP地址的分类 IP地址长度为32位,点分十进制(dotted decimal)地址: 采 ...

  8. JavaWeb框架_Struts2_(三)---->Struts2的拦截器

    2. Struts2的拦截器(使用拦截器实现权限控制) 2.1 拦截器的概述 拦截器是Struts2的核心组成部分,它可以动态的拦截Action调用的对象,类似与Servlet中的过滤器.Struts ...

  9. [转]css讲解 font-weight:bold和bolder区别

    font-weight 字体浓淡(精细)属性 该CSS属性用来设定字体的浓淡程度. 值:normal | bold | bolder | lighter | 100 | 200 | 300 | 400 ...

  10. 11.Selenium+Python案例--百度

    一.具体代码实现 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionCh ...