[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 ...
随机推荐
- 【转】C# 使用消息队列,包括远程访问
出处:http://www.cnblogs.com/80X86/p/5557801.html 近期做一个小的功能需求,用到了队列,用的时候出了很多问题,现在总结一下,希望能对有需要的人提供帮助. 我的 ...
- [ActionScript 3.0] AS3.0 将图像的Alpha通道转换为黑白图像(分离ARGB方式)
import flash.display.BitmapData; import flash.display.Bitmap; /** * 将图像的Alpha通道转换为黑白图像(分离ARGB方式) */ ...
- Codeforces 723c [贪心][乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一个n和m. 第二行给n个数. 每次操作可以把n个数中的任何一个数替代为别的数,问最少的操作次数使得1.2.3.4.5...m中的数出现的次数 ...
- ztree
http://www.s u c h s o.com/projecteactual/ztree-jiaocheng-mvc-checkbox-quanxuan-demo-down.html http: ...
- The default for KeyValuePair
if (getResult.Equals(new KeyValuePair<T,U>())) or this: if (getResult.Equals(default(KeyValueP ...
- HTML音乐播放——切歌
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Lua 5.1 参考手册
Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes 云风 译 www.codingno ...
- MessageFormat不支持{
转自 :http://zqc-0101.iteye.com/blog/1140140 MessageFormat用来格式化一个消息,通常是一个字符串,比如: String str = "I' ...
- 我要崩溃了,要解出这么一段js代码背后的东西,这真是一坨啊,别被高度欺骗了,他还有宽度!!!!!试着按下方向右键
一坨js代码: function s_gi(un, pg, ss) { var c = "s.version='H.26';s.an=s_an;s.logDebug=function(m){ ...
- 服务器响应头隐藏X-power-by
服务器响应头隐藏X-power-by 这个不是Apache或者Nginx输出的,而是由语言解析器或者应用程序框架输出的. 这个值的意义用于告知网站是用何种语言或框架编写的.例如: PHP标准输出是:X ...