操作系统第四次作业

操作系统第四次作业

问题一:Why is it important for the scheduler to distinguish I/O-bound programs from CPU-bound programs?
答:

I/O密集型程序通常具有大量的短CPU执行,而CPU密集型程序可能只有少量长CPU执行,而短CPU执行执行的频率很高。所以需要识别两种类型的程序,进而采取合适的调度算法,从而使得计算机更加高效。

问题二:

Consider the following set of processes, with the length of the CPU burst given in milliseconds:

ProcessBurst TimePriority
P1103
P211
P323
P414
P552

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.

a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive priority (a smaller priority number implies a higher priority), and RR (quantum = 1).

b. What is the turnaround time of each process for each of the scheduling algorithms in part a?

c. What is the waiting time of each process for each of the scheduling algorithms in part a?

d. Which of the algorithms in part a results in the minimum average waiting time (over all processes)?

答:

请添加图片描述
请添加图片描述

问题三:

Which of the following scheduling algorithms could result in starvation?

a. First-come, first-served

b. Shortest job first

c. Round robin

d. Priority

答:

b、d

问题四:

The traditional UNIX scheduler enforces an inverse relationship between priority numbers and priorities: The higher the number, the lower the priority. The scheduler recalculates process priorities once per second using the following function:

Priority = (Recent CPU usage / 2) + Base

where base = 60 and recent CPU usage refers to a value indicating how often a process has used the CPU since priorities were last recalculated. Assume that recent CPU usage for process P1 is 40, process P2 is 18, and process P3 is 10. What will be the new priorities for these three processes when priorities are recalculated? Based on this information, does the traditional UNIX scheduler raise or lower the relative priority of a CPU-bound process?

答:

问题一:

P1 = 40/2 + 60 = 80

P2 = 18/2 + 60 = 69

P3 = 10/2 + 60 = 65

故优先级从高到低为P3、P2、P1

问题二:

传统的UNIX调度程序是降低了CPU密集型进程的相对优先级

因为CPU密集型进程相较于I/O密集型进程占用更多的CPU时间

故最后CPU密集型进程的Priority值会比I/O密集型进程的Priority值增长地更快,优先级也降低得更快,所以相对而言,降低了了CPU密集型进程的优先级

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 实验目的 调度的实质是操作系统按照某种预定的策略来分配资源。进程调度的目的是分配CPU资源。由于进程调度程序执行的频率很高,因此调度算法的好坏直接影响到操作系统的性能。本实验的目的是编程模拟实现几种常用的进程调度算法,通过对几组进程分别使用不同的调度算法,计算进程的平均周转时间和平均带权周转时间,比较各种算法的性能优劣。 2. 实验原理 [1]. 进程调度算法描述 进程调度算法包括先来先服务调度算法、最短作业时间优先(抢占式和非抢占式)、最高响应比调度算法4种。(每个人必须做FCFS,然后在后面的三种中任选一种,即每个人必须做2种调度算法的模拟。) [2]. 衡量算法性能的参数 计算进程的平均周转时间和平均带权周转时间。 3. 实验内容 (1)编程实现本实验的程序,要求: [1]. 建立进程的进程控制块,进程控制块至少包括: a) 进程名称; b) 进程需要执行时间; c) 进入就绪队列时间; d) 进程执行开始时间 e) 进程执行结束时间 [2]. 编程实现调度算法。 [3]. 进程及相关信息的输入。这些信息可以直接从键盘上输入,也可以从文件读取。 [4]. 时间片与时间流逝的模拟。本实验需要对算法的执行计时,程序应该提供计算时间的方法。一种最简单的方法是使用键盘,比如每敲一次空格代表一个时间片的流逝。另一种方法是使用系统时钟。 [5]. 一组进程序列执行完毕,打印出结果信息。程序需要计算出每个进程的开始执行时间、结束时间、周转时间和带权周转时间,并为整个进程序列计算平均周转时间和平均带权周转时间。程序将计算结果按一定的格式显示在计算机屏幕上或输出到文件中。打印出进程调度顺序图。 [6]. 实现数据在磁盘文件上的存取功能。 (2)对下列就绪进程序列分别使用上面的几种算法进行调度,计算每种算法下的平均周转时间和平均带权周转时间。 进程号 到达时间 要求执行时间 0 0 1 1 1 35 2 2 10 3 3 5 4 6 9 5 7 21 6 9 35 7 11 23 8 12 42 9 13 1 10 14 7 11 20 5 12 23 3 13 24 22 14 25 31
现代操作系统第四版是一本经典的操作系统教材,第三章主要讲解了进程的概念、进程控制块、进程状态以及进程调度等内容。以下是第三章的主要内容概述: 1.进程的概念:进程是程序在执行过程中分配和管理资源的基本单位,每个进程都有自己的地址空间、数据栈、指令计数器、寄存器和文件描述符等。 2.进程控制块:进程控制块是操作系统内核中用于管理进程的数据结构,包含了进程的状态、进程ID、优先级、程序计数器、寄存器、内存分配情况、打开文件列表等信息。 3.进程状态:进程状态包括运行态、就绪态、阻塞态和创建态等,进程在不同状态之间转换,操作系统根据进程状态来进行进程调度。 4.进程调度:进程调度是操作系统内核中的一个重要模块,负责决定哪个进程可以获得CPU的使用权,进程调度算法包括先来先服务、短作业优先、时间片轮转等。 5.进程同步:进程同步是指多个进程之间的协作,包括互斥、信号量、管程等机制,用于保证多个进程之间的正确性和一致性。 6.进程通信:进程通信是指多个进程之间的信息交换,包括共享内存、消息队列、管道等机制,用于实现进程之间的数据传输和共享。 以下是现代操作系统第四版第三章的相关代码示例: ```c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main() { pid_t pid; int status; pid = fork(); if (pid < 0) { printf("Fork error\n"); exit(1); } else if (pid == 0) { printf("Child process\n"); exit(0); } else { printf("Parent process\n"); wait(&status); printf("Child exit status: %d\n", WEXITSTATUS(status)); } return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值