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 scp复制文件,不需要输入密码的技巧

    当两台LINUX主机之间要互传文件时可使用SCP命令来实现,建立信任关系之后可不输入密码. 把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中 假 ...

  2. Windows下运行python脚本报错“ImportError: No Module named ...”的解决方法

    之前遇到一个问题,在Pycharm或IPython之类的IDE上运行脚本正常,但是直接运行或cmd命令行运行的时候报了模块未能找到的错误--ImportError: No Module named . ...

  3. 课堂scrum站立会议

    项目名称:连连看游戏 小组名称:四大天王 开会时间 :2016年10月11日 20:20~20:40 master:张政 成员:张政,张金生,武志远,李权 站立会议内容 1.已完成的工作 window ...

  4. 黑马程序员_JAVA之银行业务调度系统

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 1.模拟实现银行业务调度系统逻辑,具体需求如下: 银行内有6个业务窗口,1 - 4号窗口为普通窗 ...

  5. the philosophy behind of the design of the STL

    The concept of STL is based on a separation of data and operations. The data is managed by container ...

  6. csdn的资源使用

    资源库: http://lib.csdn.net/

  7. PIC32MZ tutorial -- Key Debounce

    Today I accomplish a application on PIC32MZ EC Starter Kit. The feature of application is to light u ...

  8. NHibernate系列文章十七:NHibernate Session管理(附程序下载)

    摘要 NHibernate的Session的管理涉及到NHibernate的两个最重要的对象ISessionFactory和ISession.ISessionFactory的生成非常消耗资源,通常都在 ...

  9. java中Thread的 interrupt异常处理

    http://blog.csdn.net/srzhz/article/details/6804756

  10. asp.net下拉列表绑定数据库多个字段

    select ID, CONVERT(varchar(10),TBName) +','+RoomName+ ',最大人数:'+CONVERT(varchar(10),MAXNum) as ClassR ...