[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 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?的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [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. 答案: 内核在进行进程上下文切换时, 首 ...
- [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. 答案: 长期调度决定哪些进程进 ...
- [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 ...
- [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 处 ...
- UNIX高级环境编程(12)进程关联(Process Relationships)- 终端登录过程 ,进程组,Session
在前面的章节我们了解到,进程之间是有关联的: 每个进程都有一个父进程: 子进程退出时,父进程可以感知并且获取子进程的退出状态. 本章我们将了解: 进程组的更多细节: sessions的内容: logi ...
- Linux process authority、the security risks in running process with high authority
catalog . Linux进程权限原理 . 最小权限原则 - 进程降权运行最佳实践 . 进程权限控制包含的攻防向量 . 进程高权限安全风险检查技术方案 1. Linux进程权限原理 我们知道,Li ...
随机推荐
- jquery是如何架构的.
心里一直有个疑问. jquery是如何做到一个jQuery即可以当方法用比如$();又可以当对象用$.extend(); 现在总结一下吧 function method(){} var m=new m ...
- IDEA中PlantUML的使用
PlantUML官网地址:http://www.plantuml.com/ IDEA中安装PlantUML Plugins File-->Settings-->Plugins-->I ...
- 11.tftp和nfs服务器
宿主机产生嵌入式软件的机器 运行程序的是目标机上运行 基于网络的下载 目标机通过tftp下载到目标机 1. 安装tftp依赖xinetd [root@cfm880 Packages]# rpm -iv ...
- 有了第一台自己开发的pro,开心,明天分享最近整理逆向分析ios的一些东西
最近都在忙于ios深入研究,研究别人的代码,别人的app.然后顺藤摸瓜的找到了关键:逆向,动态特性等. 相关工具:reveal, cycript等. 特别感谢前人的分享,为了打开学习ios的另外一扇大 ...
- Application tried to present a nil modal view controller on target “Current View Controller”解决方案
情景再现 1,自定义一个storyboard: 打开xcode,按下cmd+N,新建一个Storyboard--->next 将新建立的storyboard命名为:TestViewControl ...
- Mysql数据库的使用经验总结
1. 对mysql插入中文的时候显示乱码,搞了很多天,把服务端.客户端和数据库的编码全改为u8了又重新创建数据库和表还是不行,到最后却发现没有乱码!原来只是windows的cmd没有支持u8,换个客户 ...
- php函数的引用返回
<?php function &test(){ static $b = 1; $b += 2; return $b; } $a = &test(); $a =8; $c = te ...
- VirtualBox 内的 Ubuntu Server 虚拟机网络配置
环境: 宿主机:Windows 7,单网卡: 虚拟机:ubuntu-14.04.1-server-amd64: 宿主机上网是连接的路由器,IP 地址是通过 DHCP 服务自动获取的: 基本情况: Ub ...
- Mysql错误信息汇总
目录: 1. Every derived table must have its own alias 内容: 1. Every derived table must have its own alia ...
- iframe自动适应高度1
js: function iFrameHeight() { var ifm= document.getElementById("iframepage"); var subWeb = ...