操作系統恐龍書第十版課後答案ch05

5.1 A CPU-scheduling algorithm determines an order for the execution of its scheduled processes. Given n processes to be scheduled on one processor, how many different schedules are possible? Give a formula in terms of n.

n! (n factorial = n × n – 1 × n – 2 × ... × 2 × 1).

5.2 Explain the difference between preemptive and nonpreemptive scheduling.
搶佔式調度允許在進程執行過程中中斷該進程,將CPU從該進程中取走,並分配給另一個進程。非搶佔式調度確保進程僅在完成其當前的CPU執行時才放棄對CPU的控制。
5.3 Suppose that the following processes arrive for execution at the times indicated. Each process will run for the amount of time listed. In answering the questions, use nonpreemptive scheduling, and base all decisions on the information you have at the time the decision must be made.
a. What is the average turnaround time for these processes with the FCFS scheduling algorithm? b. What is the average turnaround time for these processes with the SJF scheduling algorithm? c. The SJF algorithm is supposed to improve performance, but notice that we chose to run process P1 at time 0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remember that processes P1 and P2 are waiting during this idle time, so their waiting time may increase. This algorithm could be known as future-knowledge scheduling.

a. 10.53

b. 9.53

c. 6.86

請記住,周期時間是指完成時間減去到達時間,因此您必須減去到達時間期時間。如果您忘記減去到達時間,對於先來先服務(FCFS)算法,周期時間將是11。

5.4 Consider the following set of processes, with the length of the CPU burst time given in milliseconds:
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 larger priority number implies a higher priority), and RR (quantum = 2).
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 these scheduling algorithms?
d. Which of the algorithms results in the minimum average waiting time (over all processes)?

d. SJF有最短的等待時間

5.5 The following processes are being scheduled using a preemptive, roundrobin scheduling algorithm.
Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. In addition to the processes listed below, the system also has an idle task (which consumes no CPU resources and is identified as Pidle). This task has priority 0 and is scheduled whenever the system has no other available processes to run. The length of a time quantum is 10 units. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue.

a. Show the scheduling order of the processes using a Gantt chart.

b. What is the turnaround time for each process?

c. What is the waiting time for each process?

d. What is the CPU utilization rate?

b. P1: 20-0 - 20, P2: 80-25 = 55, P3: 90 - 30 = 60, P4: 75-60 = 15, P5: 120-100 = 20, P6: 115-105 = 10

c. P1: 0, p2: 40, P3: 35, P4: 0, P5: 10, P6: 0

d. 105/120 = 87.5 percent.

5.6 What advantage is there in having different time-quantum sizes at different levels of a multilevel queueing system?

需要更頻繁服務的進程,例如交互式進程,比如編輯器,可以在具有較小時間片的隊列中。而不需要頻繁服務的進程可以在具有較大時間片的隊列中,這樣需要較少的上下文切換來完成處理,因此更有效地利用了計算機。

5.7 Many CPU-scheduling algorithms are parameterized. For example, the RR algorithm requires a parameter to indicate the time slice. Multilevel feedback queues require parameters to define the number of queues, the scheduling algorithms for each queue, the criteria used to move processes between queues, and so on. These algorithms are thus really sets of algorithms (for example, the set of RR algorithms for all time slices, and so on). One set of algorithms may include another (for example, the FCFS algorithm is the RR algorithm with an infinite time quantum). What (if any) relation holds between the following pairs of algorithm sets?
a. Priority and SJF
b. Multilevel feedback queues and FCFS
c. Priority and FCFS d. RR and SJF

a. 最短的工作擁有最高的優先順序。

b. MLFQ 中最低層是 FCFS。

c. FCFS 將最高的優先順序給存在時間最長的工作。

d. 無。

5.8 Suppose that a CPU scheduling algorithm favors those processes that have used the least processor time in the recent past. Why will this algorithm favor I/O-bound programs and yet not permanently starve CPU-bound programs?

這將有利於I/O密集型程序,因為它們請求的CPU爆發相對較短;然而,CPU密集型程序將不會被餓死,因為I/O密集型程序會相對頻繁地釋放CPU以執行I/O操作。

5.9 Distinguish between PCS and SCS scheduling

PCS(Process Control System)排程是針對進程本身的局部排程,用於線程庫將線程排程到可用的輕量進程(LWP)上。SCS(System Call State)排程則用於操作系統排程核心線程。在使用多對一(many-to-one)或多對多(many-to-many)模型的系統中,這兩種排程模型基本上是不同的。在使用一對一(one-to-one)模型的系統中,PCS和SCS是相同的。

5.10 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, for process P2 is 18, and for 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?

分配給進程的優先順序將分別為80、69和65。調度器會降低CPU密集型進程的相對優先順序。

5.11 Of these two types of programs:
a. I/O-bound
b. CPU-bound which is more likely to have voluntary context switches, and which is more likely to have nonvoluntary context switches? Explain your answer.

a. I/O-bound(I/O密集型) - 自願的,因為該程序更有可能自願地釋放CPU,等待I/O可用。

b. CPU-bound(CPU密集型) - 非自願的,因為該程序很可能會在其整個時間片內使用CPU。

5.12 One technique for implementing lottery scheduling works by assigning processes lottery tickets, which are used for allocating CPU time. Whenever a scheduling decision has to be made, a lottery ticket is chosen at random, and the process holding that ticket gets the CPU. The BTV operating system implements lottery scheduling by holding a lottery 50 times each second, with each lottery winner getting 20 milliseconds of CPU time (20 milliseconds × 50 = 1 second). Describe how the BTV scheduler can ensure that higher-priority threads receive more attention from the CPU than lower-priority threads.

通過給高優先級進程分配更多的彩票票券。

5.13 Consider the exponential average formula used to predict the length of the next CPU burst. What are the implications of assigning the following values to the parameters used by the algorithm?
a. α = 0 and τ0 = 100 milliseconds
b. α = 0.99 and τ0 = 10 milliseconds

當 α = 0,τ0 = 100 毫秒時,該公式總是對下一個CPU爆發預測為100毫秒。當 α = 0.99,τ0 = 10 毫秒時,進程的最近行為受到比過去歷史更多的權重。因此,排程算法幾乎不記憶過去,只是對下一個CPU執行的量預測為前一個爆發的長度。

5.14 A variation of the round-robin scheduler is the regressive round-robin scheduler. This scheduler assigns each process a time quantum and a priority. The initial value of a time quantum is 50 milliseconds. However, every time a process has been allocated the CPU and uses its entire time quantum (does not block for I/O), 10 milliseconds is added to its time quantum, and its priority level is boosted. (The time quantum for a process can be increased to a maximum of 100 milliseconds.) When a process blocks before using its entire time quantum, its time quantum is reduced by 5 milliseconds, but its priority remains the same. What type of process (CPU-bound or I/O-bound) does the regressive round-robin scheduler favor? Explain.

這種排程器將偏向CPU密集型進程,因為它們會在消耗整個時間片的同時獲得更長的執行時間,並在每次消耗整個時間片時提高優先順序。這種排程器不會懲罰I/O密集型進程,因為它們在消耗整個時間片之前很可能會阻塞以進行I/O操作,但它們的優先順序保持不變。

5.15 The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm.
Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. The scheduler will execute the highestpriority process. For processes with the same priority, a round-robin scheduler will be used with a time quantum of 10 units. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue.
a. Show the scheduling order of the processes using a Gantt chart.
b. What is the turnaround time for each process?
c. What is the waiting time for each process?

a. No Answer

b. P1 = 15, P2 = 95, P3 = 55, P4 = 55, P5 = 5, P6 = 15

c. P1 = 0, P2 = 75, P3 = 35, P4 = 35, P5 = 0, P6 = 0

5.16 Which of the following scheduling algorithms could result in starvation?
a. First-come, first-served
b. Shortest job first
c. Round robin
d. Priority

短作業優先(Shortest-job-first)和基於優先級的排程算法可能導致餓死現象。

5.17 Consider a system running ten I/O-bound tasks and one CPU-bound task. Assume that the I/O-bound tasks issue an I/O operation once for every millisecond of CPU computing and that each I/O operation takes 10 milliseconds to complete. Also assume that the context-switching overhead is 0.1 millisecond and that all processes are long-running tasks. Describe the CPU utilization for a round-robin scheduler when: a. The time quantum is 1 millisecond b. The time quantum is 10 milliseconds

a. 時間片為1毫秒:無論選擇調度哪個進程,調度器每次切換上下文都會產生0.1毫秒的開銷。這導致CPU利用率為1/1.1 * 100 = 91%。

b. 時間片為10毫秒:I/O密集型任務在使用1毫秒時間片後會發生一次上下文切換。因此,循環遍歷所有進程所需的時間為10 * 1.1 + 10.1(因為每個I/O密集型任務在執行1毫秒後會發生一次上下文切換,而CPU密集型任務在發生上下文切換之前會執行10毫秒)。因此,CPU利用率為20/21.1 * 100 = 94%。

5.18 Explain the how the following scheduling algorithms discriminate either in favor of or against short processes:
a. FCFS
b. RR
c. Multilevel feedback queues

a. FCFS(First-Come, First-Served) - 歧視短作業,因為任何在長作業之後到達的短作業都將具有較長的等待時間。

b. RR(Round Robin) - 對所有作業平等對待(給予它們相等的CPU時間片),因此短作業將能夠更快地離開系統,因為它們將優先完成。

c. 多級反饋隊列(Multilevel Feedback Queues)與RR算法類似,它們對短作業持有有利態度。

5.19 Assume that an SMP system has private, per-processor run queues. When a new process is created, it can be placed in either the same queue as the parent process or a separate queue.
a. What are the benefits of placing the new process in the same queue as its parent?
b. What are the benefits of placing the new process in a different queue?

a. 如果子進程訪問與其父進程相同的內存,它可能能夠充分利用處理器的緩存內容。

b. 新進程可以放置在具有較小工作負載的隊列中,從而在創建新進程時實現負載平衡。

5.20 Using the Windows scheduling algorithm, determine the numeric priority of each of the following threads.
a. A thread in the REALTIME PRIORITY CLASS with a relative priority of NORMAL
b. A thread in the ABOVE NORMAL PRIORITY CLASS with a relative priority of HIGHEST
c. A thread in the BELOW NORMAL PRIORITY CLASS with a relative priority of ABOVE NORMAL

a. 26

b. 8

c. 14

5.21 Assume that two tasks, A and B, are running on a Linux system. The nice values of A and B are −5 and +5, respectively. Using the CFS scheduler as a guide, describe how the respective values of vruntime vary between the two processes given each of the following scenarios: • Both A and B are CPU-bound. • A is I/O-bound, and B is CPU-bound. • A is CPU-bound, and B is I/O-bound.

由於A的優先順序高於B,對於A來說,虛擬運行時間(vruntime)將比對於B來說變化較慢。如果A和B都是CPU密集型的(即,它們都在分配給它們的時間內使用CPU),通常情況下,A的vruntime將小於B的vruntime,因此A將具有更高的運行優先順序,優先運行而不是B。

在這種情況下,對於A來說,vruntime將比對於B來說小得多,因為(1)由於優先級差異,vruntime對於A而言會變化得比較慢,而(2)A需要較少的CPU時間,因為它是I/O密集型。

然而,這種情況並不是那麼明確,B可能最終會運行優於A,因為它使用處理器時間少於A,其vruntime的值實際上可能會小於A的vruntime值

5.22 Explain why interrupt and dispatch latency times must be bounded in a hard real-time system

停止一個進程並啟動另一個需要執行以下任務:保存當前正在執行的指令、確定中斷的類型、保存當前進程的狀態,然後調用適當的中斷服務程序。調度延遲是停止一個進程並啟動另一個的成本。為確保實時任務能夠立即得到處理,必須將中斷和調度延遲時間都盡量減小。

此外,有時在修改內核數據結構時會禁用中斷,因此無法立即處理中斷。對於硬實時系統,必須將禁用中斷的時間段限制在一定範圍內,以確保所需的服務質量。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
操作系统是计算机系统中最基本的软件之一,它负责管理和协调计算机硬件资源,提供更高层次的抽象,使用户能够方便地使用计算机。操作系统的主要功能包括进程管理,内存管理,文件系统管理和设备管理。 进程管理是操作系统的核心功能之一。它负责创建、终止和调度进程,以及管理进程之间的通信和同步。通过进程管理,操作系统可以控制程序的执行顺序,保证多个程序可以同时运行,并且能够相互合作。 内存管理是操作系统的另一个重要功能。它负责管理计算机的内存资源,将内存划分为多个区域,为进程分配内存空间,并且提供内存的分配和回收功能。内存管理还负责虚拟内存的实现,通过将部分程序从内存中换出到磁盘上的交换区,实现了对内存资源的合理利用。 文件系统管理是操作系统的一个关键组成部分。它提供了一种组织和存储文件的方式,使得用户可以通过文件名来访问和管理文件。文件系统管理还包括文件的创建、删除、复制和移动等操作,以及对文件的读写权限的管理。 设备管理是操作系统的另一个重要功能。它负责管理计算机的输入输出设备,包括硬盘、键盘、鼠标、打印机等。设备管理还负责调度和控制设备的访问,以保证多个设备可以同时进行操作,并且能够高效地响应用户的请求。 操作系统还提供了用户接口,使用户能够方便地与计算机进行交互。用户可以通过命令行界面或者图形界面来操作计算机,执行各种任务,如运行程序、管理文件、配置系统等。 总而言之,操作系统是计算机系统中的一个关键组成部分,它负责管理和协调计算机的各种资源,为用户提供一个方便、高效和可靠的计算环境。操作系统的功能包括进程管理、内存管理、文件系统管理和设备管理,通过这些功能,操作系统可以实现对计算机的全面控制和管理。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值