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

答案: 共16个进程。

解析:

  根据之前所学到的关于fork的知识去画进程图, 要注意的一点就是, fork的子进程的程序计数器里的指令和父进程的相同, 所以每次fork之后, 子进程里i的值都会继续增加。例如, 第一个进程, i=0时, fork的子进程的i会继续++, 从1开始。 下面是此题的进程图。

jk

红色的数字是进程的PID, PID是我当时写的一个程序得到的, 代码如下:

 #include<stdio.h>
#include<unistd.h>
#include<sys/types.h> int main()
{
char p = 'c';
int i;
FILE *fp;
pid_t pid;
printf("%d\n", getpid()); fp = fopen("data.txt", "a+");
for(i = ; i < ; i++){
if(fork() > ){
printf("%c %d\n", p = 'p', i);
}
else
printf("%c %d\n", p, i);
wait(NULL);
}
fprintf(fp, "%d %d\n", getppid(), getpid()); fclose(fp);
return ;
}

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

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

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

  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. UNIX高级环境编程(12)进程关联(Process Relationships)- 终端登录过程 ,进程组,Session

    在前面的章节我们了解到,进程之间是有关联的: 每个进程都有一个父进程: 子进程退出时,父进程可以感知并且获取子进程的退出状态. 本章我们将了解: 进程组的更多细节: sessions的内容: logi ...

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

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

随机推荐

  1. Linux中cp和scp命令的使用方法

    Linux为我们提供了两个用于文件copy的命令,一个是cp,一个是scp,但是他们略有不同. cp --- 主要是用于在同一台电脑上,在不同的目录之间来回copy文件 scp --- 主要是在不同的 ...

  2. Drools给日志打标签

    一.定义日志模型 public class Logger { // 日志编号 private String id; // 目标IP private String targetIp; // 目标端口 p ...

  3. Selenium

    Selenium可以抓取完整的页面的html但是request 和java的url不能抓的很完整. selenium的方法是dirver.page_source

  4. No.6__C#

    第六周 周一:今天特别开心,因为来公司的第一个任务完成了,虽然是在组长的帮助下完成的.但是,还是有很多收获,在实际工作中遇到的问题和麻烦远远超出了书本知识 有些问题简直让人抓狂.现在,上班空余期间,也 ...

  5. oracle查询小结

    一.查询某表中某列值相同的记录: select * from t_acct_map where acct_id in (     select acct_id from t_acct_map grou ...

  6. iOS开发--一些UITabBarItem属性的设置[转]

    1.改变UITabBarItem 字体颜色 [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionary dictionaryWithOb ...

  7. Archlinux 添加无线网络

    From: https://wiki.archlinux.org/index.php/Beginners%27_Guide_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%8 ...

  8. ArcGIS for Flex中引入google map作底图

    上篇文章到在ArcGIS View中引入google map,这里讲ArcGIS for Flex中引入google map作底图. 同样道理,以google map作底图,需要编写继承自TiledM ...

  9. Sass浅谈

    对于一名前端开发来说,CSS并不陌生,几乎每天都在和CSS打交道.相处久了就会觉得CSS有些许的机械化,有些许的无趣:就会觉得写CSS很多时候都是在做一些复制粘贴性的工作,布局排版,颜色设置,边框属性 ...

  10. JavaScript笔记:DOM基础

    一.什么是DOM DOM全称是document object model(文档对象模型).在网页上,组织页面(或文档)的对象被组织在一个树形结构中,用来表示文档中对象的标准模型就称为DOM.通俗的说D ...