[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 ...
随机推荐
- Sqlite: FOREIGN KEY constraint failed on remove的错误原因。
sqlite外键约束中.restrict约束:如果要删除父表,则子表需空. 如果没有定义约束.会报错,需设置一个约束.
- eclipse中如何关闭运行时自动保存?
Eclipse没有提供自动保存的功能,只能自己写脚本每隔多久保存一次,或监听修改即保存.设置方法:1.打开:preferences>run/debug>launching2.选择save ...
- [转载]Macaca 测试 Android 应用:UIAutomator
在用macaca进行自动化测试,想试一下移动端测试,看到这篇文章,尝试一下. 前言 用 Macaca 可以快速.便捷地进行安卓 native 的自动化测试,用简洁的 js 语法,写下用例,然后执行 M ...
- POS管理系统之新增设备入库
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- myeclipse搭建SSH框架
搭建SSH框架 Struts+hibernater+spring架构(myeclipse) 右击,首先加入spring,加入hibernater,再加入struts2 复制jar包(把tomcat发布 ...
- jexus
Jexus web server V5.1 安装配置要点 一.Jexus简介:Jexus web server for linux 是一款基于.NET兼容环境,运行于Linux/unix操作系统之上, ...
- myeclipse 导入JAVA项目
说白了.就是别人给你一份写好的文件你不会用是吧?新手都是这样的.很正常..这样.咱们一步一步的来.邮件项目工程栏,选择import,选择General,选择Existing Projects into ...
- 第一零二天上课 PHP TP框架 引入文件路径问题和调用验证码的方式
外部文件引入到视图模板的方式 1,将外部文件放在Public文件夹下,用load标签引入 2,在模板出书写引入代码(方法有很多,只有以下方法不容易出问题) <load h ...
- scala.collection.immutable.HashSet$.empty()Lscala/collection/immutable/HashSet
最近重新搭了spark环境.在Master上使用了IDEA来写代码.确实很方便.我用的是hadoop2.6.spark1.5.1forhadoop2.6. scala之前用的是2.11.0老是报这个错 ...
- JavaWeb 输出九九乘法表,三角形,菱形
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...