操作系统导论习题解答(4. Processes)

Homework (Simulation)

This program, process-run.py, allows you to see how process states change as programs run and either use the CPU (e.g., perform an add instruction) or do I/O (e.g., send a request to a disk and wait for it to complete). See the README for details.

Target

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027183400117.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA==,size_16,color_FFFFFF,t_70#pic_center)

Introduction

type python process-run.py -h in the command, you should see:

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027183916151.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA,size_16,color_FFFFFF,t_70#pic_center)
在这里插入图片描述
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027185121933.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA
,size_16,color_FFFFFF,t_70#pic_center)

Question & Answer

1

在这里插入图片描述

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027185527260.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA==,size_16,color_FFFFFF,t_70#pic_center)
The CPU utilization is 100%.

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027185740148.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA==,size_16,color_FFFFFF,t_70#pic_center)

2

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027185956559.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA,size_16,color_FFFFFF,t_70#pic_center)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027190138396.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA
,size_16,color_FFFFFF,t_70#pic_center)
It takes 10 clock ticks to complete both processes.

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027190641796.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA==,size_16,color_FFFFFF,t_70#pic_center)
First, process 0 was run, it took 4 clock ticks. Then process 1 issued an I/0 request, the CPU received and blocked process 1, it took 1 clock tick. Next the I/O took 4 clock ticks, and finally the CPU unblocked the process 1, process 1 was done, it took 1 clock tick.

3

在这里插入图片描述
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027193114524.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA==,size_16,color_FFFFFF,t_70#pic_center)
在这里插入图片描述
Process 0 issued an I/O request, the CPU blocked it and started I/O operations, it took 1 clock tick. When I/Os were running, process 1 issued the CPU request, after 4 clock ticks, I/Os and CPU finished. It takes a total of 6 clock ticks.

4

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027194224270.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA,size_16,color_FFFFFF,t_70#pic_center)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/202010271944032.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA
,size_16,color_FFFFFF,t_70#pic_center)
When process 0 is doing I/0, the system will not switch to process 1, instead waiting until the process 0 is completely finished.

5

在这里插入图片描述
在这里插入图片描述
It is the same as question 3.

6

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027195002141.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA,size_16,color_FFFFFF,t_70#pic_center)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/2020102719562977.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA
,size_16,color_FFFFFF,t_70#pic_center)
The system resources are not being effectively utilized.

7

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027195816627.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA,size_16,color_FFFFFF,t_70#pic_center)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20201027195902671.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MTcwMzE3NA
,size_16,color_FFFFFF,t_70#pic_center)
The difference between the two is whether the CPU accepts the next I/O request or runs the process instruction after the I/O operation is executed. Since the default mode SWITCH_ON_IO is adopted, the CPU executes instructions and I/O operations are performed simultaneously, so IO_RUN_IMMEDIATE is 1 clock tick faster.

posted @ 2022-10-14 18:58  astralcon  阅读(316)  评论(0)    收藏  举报