Understanding Operating Systems, 6th edition Research Topics– Chapter 4 Answers will vary. Look for credible references and evidence that the student thoughtfully evaluated the available research. Exercises - 4 1. Figure 4.12 is a simplified process model of you, in which there are only two states: sleeping and waking. You make the transition from waking to sleeping when you are tired, and from sleeping to waking when the alarm clock goes off. There can be many answers, look for originality here. One solution is shown below. tired hungry Waking Sleeping alarm rings bored Eating satisf ied anxiety someone w atching snack time Daydreaming Studying energy boost strain 2. Describe context switching in lay terms and identify the process information that needs to be saved, changed, or updated when context switching takes place? Context switching is the passing of sufficient information to allow one page to be interrupted so another page can be moved into memory for processing. Essentially, during a context switch, the critical processing information for the page about to be replaced is saved in its Process Control Block, so that later, when it’s allowed to continue, it can pick up where it left off. The saved information includes the process identification, its status, and its state (which includes the process status work, register contents, main memory resources, other allocated resources, and process priority). Answers to Exercises Exercises - 4 Page 1 Understanding Operating Systems, 6th edition 3. Five jobs (A, B, C, D, E) are already in the READY queue waiting to be processed. Their estimated CPU cycles are respectively: 2, 10, 15, 6, and 8. Using SJN, in what order should they be processed? Using SJN, and assuming the jobs all are ready to go, the order of processing depends only on the length of the estimated processing time. Therefore, the answer is: A (2 cycles), D (6 cycles), E (8), B (10), and C (15). 4. A job running in a system, with variable time quantums per queue, needs 30 milliseconds to run to completion. If the first queue has a time quantum of 5 milliseconds and each queue thereafter has a time quantum that is twice as large as the previous one, how many times will the job be interrupted and on which queue will it finish its execution? It will be interrupted two times and will finish its execution in the third queue. Queue 1 Queue 2 Queue 3 Queue 4 5ms 10ms 20ms 40ms Etc. 5. Describe the advantages of having a separate queue for Print I/O interrupt and for Disk I/O as illustrated in Figure 4.4. The Disk I/O can accommodate several jobs requiring nonsequential processing because processing of each job can be interrupted, or not, depending on the allocation scheme. These jobs don’t need to be processed from beginning to end at one time on one processor. On the other hand, the Print I/O may included dedicated devices that would not (ordinarily) interleave the printed pages from more than one job. These tasks are completed from beginning to end before the printer is assigned to another job. 6. Given the following information: Finish times are shown on the right. Job A B C D E F G Arrival Time 0 1 2 4 5 7 8 Answers to Exercises CPU Cycle 2 12 4 1 8 5 3 Finish Time (answer) 2 35 6 7 23 12 15 Exercises - 4 Page 2 Understanding Operating Systems, 6th edition 7. Given the following information: Job Arrival Time 0 2 3 6 9 A B C D E CPU Cycle 10 12 3 1 15 Draw a timeline for each of the following scheduling algorithms. (It may be helpful to first compute a start and finish time for each job.) a. FCFS Here are the arrival and finish times. Job A B Arrival time 0 2 Finish time 10 22 Here is a time line from 0 to 41 seconds. A 0 B C 3 25 C D D 6 26 E 26 22 25 10 E 9 41 41 b. SJN Here are the arrival and finish times. Job Arrival time Finish time A 0 10 A 0 B 2 26 DC 11 10 C 3 14 B 14 D 6 11 E 9 41 E 26 41 c. SRT Note: SRT is preemptive and interrupts a job when another job arrives that has a shorter remaining CPU time required to finish. Therefore, Job A begins, and when Job B arrives, the two jobs are compared: by this time requires only 8 more cycles to finish, while Job B requires 12, so Job A is allowed to continue until cycle 3 when Job C arrives. Answers to Exercises Exercises - 4 Page 3 Understanding Operating Systems, 6th edition Job Arrival time Finish time A C D 0 3 A 0 14 B 2 26 A C 3 6 D 6 7 B 6 7 E 9 41 E 14 26 41 d. Round robin (using a time quantum of 5, ignore context switching and natural wait) Job Arrival time Finish time A1 0 A 0 24 B1 5 B 2 36 C D E1 14 10 13 C 3 13 A2 19 B2 24 E2 29 D 6 14 B 3 E 9 41 E3 36 34 41 8. Using the same information from Exercise 7, calculate which jobs will have arrived ready for processing by the time the first job is finished or interrupted using each of the following scheduling algorithms. a. FCFS All of the jobs will have arrived: A, B, C, D, E. b. SJN All of the jobs will have arrived: A, B, C, D, E. c. SRT Jobs B & C will have arrived at Time 2, but Job A is not interrupted. Job C arrives at Time 3 and interrupts Job A. d. Round robin (using a time quantum of 5, ignore context switching and natural wait) Job A is interrupted at Time 5 by which time Jobs B & C have arrived for processing. 9. Using the same information given for Exercise 7, compute the waiting time and turnaround time for every job for each of the following scheduling algorithms (ignoring context switching overhead). a. FCFS Job Answers to Exercises A B C Exercises - 4 D E Page 4 Understanding Operating Systems, 6th edition Turnaround time (finish-start time) Total waiting time (finish-start time - CPU time) b. SJN 10 20 22 20 32 0 8 19 19 17 Job Turnaround time (finish-start time) Total waiting time (finish-start time - CPU time) c. SRT A 10 B 24 C 11 D 5 E 32 0 12 8 4 17 Job A B Turnaround time 14 24 (finish-start time) Total waiting time 4 12 (finish-start time - CPU time) d. Round robin (using a time quantum of 2) C 3 D 1 E 32 0 0 17 Job Turnaround time (finish-start time) Total waiting time (finish-start time - CPU time) A 30 B 34 C 9 D 1 E 32 20 22 6 0 17 Advanced Exercises 10. Consider a variation of round robin in which a process that has used its full time quantum is returned to the end of the READY queue, while one that has used half of its time quantum is returned to the middle of the queue and one that has used one-fourth of its time quantum goes to a place one-fourth of the distance away from the beginning of the queue. a. What is the objective of this scheduling policy? The objective is to satisfy the needs of interactive processes, which generate a great deal of I/O. By moving the I/O-bound process closer to the head of the READY queue the response time is improved. Answers to Exercises Exercises - 4 Page 5 Understanding Operating Systems, 6th edition b. Discuss the advantage and disadvantage of its implementation. Advantages: I/O-bound jobs are favored and terminate faster. It achieves good and relatively evenly distributed terminal response time. Disadvantages: CPU-bound jobs or those without interactive sequences are subject to relatively long turnaround and waiting times. However, such jobs may be best run in batch mode. 11. In a single-user dedicated system, such as a personal computer, it’s easy for the user to determine when a job is caught in an infinite loop. The typical solution to this problem is for the user to manually intervene and terminate the job. What mechanism would you implement in the Process Scheduler to automate the termination of a job that’s in an infinite loop? Take into account jobs that legitimately use large amounts of CPU time; for example, one “finding the first 10,000 prime numbers.” A simple solution would be to set a maximum CPU time, which is compared to the accrued CPU time of each job. If a job's accrued CPU time is equal to (or exceeds) this maximum then it is terminated. Users would be responsible for overriding this default maximum CPU time when starting their jobs so that CPU-bound jobs would not be terminated prematurely. 12. Some guidelines for selecting the right time quantum were given in this chapter. As a system designer, how would you know when you have chosen the best time quantum? What factors would make this time quantum best from the the system’s point of view? When the interactive processes generate short response times, when system resources are equitably shared among processes, when the majority of short processes execute within one time quantum. Interactive users are satisfied with short response times and quick completion of their jobs. The optimal time quantum would be set to satisfy these needs. A good time quantum should minimize the number of context switches thus minimizing overhead and freeing the processor to spend more time performing a user's computations. The optimal time quantum varies from system to system, it varies under different loads, and it also varies from process to process. 13. Using the process state diagrams of Figure 4.2 illustrating a non, explain why there’s no transition: a. From the READY state to the WAITING state. There is no transition from READY to WAITING because all processes in the READY queue are selected by the Process Scheduler to run (or execute). b. From the WAITING state to the RUNNING state. There is no transition from WAITING to RUNNING because when I/O, or some other factor that had caused the process to wait, is complete then the Process Scheduler puts the process back into the READY queue from which all processes are retrieved for execution. Answers to Exercises Exercises - 4 Page 6 Understanding Operating Systems, 6th edition Programming Exercises Exercises 14 and 15 are an outcome of the paper-and-pencil exercises done previously (in exercises 7, 8 and 9). At this point, the students should have an understanding of the steps needed to implement each one of the scheduling algorithms. We hope that the students’ comparisons between the outputs will generate some discussion about preemption overhead and its impact on turnaround time. Answers to Exercises Exercises - 4 Page 7