Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
51 views8 pages

Chapter4 Exercise QnA

The document contains exercises and research topics related to operating systems, focusing on multi-core technology, processor comparisons, and various scheduling algorithms. It includes detailed questions and answers on processes, threads, job scheduling, and turnaround times using different algorithms like FCFS, SJN, and round robin. Additionally, it discusses advanced scheduling policies and their implications for system performance and user experience.

Uploaded by

Abdullah Opadeji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views8 pages

Chapter4 Exercise QnA

The document contains exercises and research topics related to operating systems, focusing on multi-core technology, processor comparisons, and various scheduling algorithms. It includes detailed questions and answers on processes, threads, job scheduling, and turnaround times using different algorithms like FCFS, SJN, and round robin. Additionally, it discusses advanced scheduling policies and their implications for system performance and user experience.

Uploaded by

Abdullah Opadeji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Understanding Operating Systems, 7th edition

Chapter 4 Exercises

Research Topics

A. Multi­core technology can often, but not necessarily always, make applications run
faster. Research some real­life computing environments that are expected to benefit
from multi­core chips and briefly explain why. Cite your academic sources.

B. Compare two processors currently being produced for laptop computers. Use standard
industry benchmarks for your comparison and briefly list the advantages and
disadvantages of each. You can compare different processors from the same
manufacturer (such as two Intel processors) or different processors from different
manufacturers (such as Intel and AMD).

Exercises

1. Compare and contrast a process and a thread. ANS: They are similar in that both can
execute instructions, but while a thread can be run within a process, a thread cannot
run independently of its process. The process is the more robust entity as it is
allocated the resources that are available to the thread, and it runs for longer periods
of time. The thread is a lightweight entity that runs according to the dictates of the
process.

2. Which scheduler is responsible for scheduling threads in a multithreading system?


ANS: Thread scheduling is performed by the process scheduler, not the job scheduler.
For the operating systems described in the book, there is not a thread scheduler.

3. Five jobs arrive nearly simultaneously for processing and their estimated CPU cycles
are, respectively: Job A = 12, Job B = 2, Job C = 15, Job D = 7, and Job E = 3 ms.

a. Using FCFS, and assuming the difference in arrival time is negligible, in what order
would they be processed? What is the total time required to process all five jobs?
What is the average turnaround time for all five jobs?
ANS: Job Order: Job A, Job B, Job C, Job D, and Job E ms.
Total time = 39 ms.
Average time = 26 ms.

UOS, 7e Ann McIver McHoes Chapter Four, Page 1


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Understanding Operating Systems, 7th edition

b. Using SJN, and assuming the difference in arrival time is negligible, in what order
would they be processed? What is the total time required to process all five jobs?
What is the average turnaround time for all five jobs?
ANS: Job Order: Job B, Job E, 7Job D Job A, Job C.
Total time = 39 ms.
Average time = 16.4 ms.

4. Assume that a multi­level queue system with a variable time quantum per queue, and
that the incoming job needs 50 ms to run to completion. If the first queue has a time
quantum of 5 ms 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? Explain how much time it spends in each queue.
ANS: The job will be interrupted 3 times and will finish on Queue 4.

Time spent: Queue 1 = 5 ms, Queue 2 = 10 ms, Queue 3 = 20 ms, Queue 4 = 15 ms.

5. Using the same multi­level queue system from the previous exercises, if a job needs
130 ms to run to completion, how many times will the job be interrupted and on
which queue will it finish its execution? Does it matter if there are other jobs in the
system? ANS: Job is Interrupted 4 times and Finishes on Queue 5. Queue 1 = 5 ms,
Queue 2 = 10 ms, Queue 3 = 20 ms, Queue 4 = 40 ms, Queue 5 = 55 ms.
The number of other jobs competing with this one makes no difference using this
algorithm.

6. Assume that your system has one queue for jobs waiting for printing and another
queue for those waiting for access to a disk. Which queue would you expect to have
the faster response? Explain your reasoning.

7. Using SJN, calculate the start time and finish time for each of these seven jobs:

Job Arrival Time CPU Cycle ANSWER


A 0 2 Start Time: 0
Finish Time: 2
B 1 11 Start: 22 Finish: 33
C 2 4 Start: 2 Finish: 6
D 4 1 Start: 6 Finish: 7

UOS, 7e Ann McIver McHoes Chapter Four, Page 2


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Understanding Operating Systems, 7th edition

E 5 9 Start: 7 Finish: 16
F 7 4 Start: 18 Finish: 22
G 8 2 Start: 16 Finish: 18

8. Given the following information:


Job Arrival CPU
Time Cycle
A 0 15
B 2 2
C 3 14
D 6 10
E 9 1
Calculate which jobs will have arrived ready for processing by the time the first job is
finished or first interrupted using each of the following scheduling algorithms.

a. FCFS ANS: By the time the first job relinquishes the CPU, all of the jobs will
have arrived, at Time 15

b. SJN ANS: By the time the first job relinquishes the CPU, all of the jobs will
have arrived, at Time 15

c. SRT ANS: By the time the first job relinquishes the CPU, Only Job B will
have arrived, at Time 2

d. Round robin (use a time quantum of 5, but ignore the time required for context
switching and natural wait) ANS: By the time the first job relinquishes the CPU, Only
Jobs B & C will have arrived, at Time 5

9. Using the same information from the previous exercise, calculate the start time and finish
time for each of the five jobs using each of the following scheduling algorithms. <Answers
are all shown in the table below>

a. FCFS

b. SJN

c. SRT

UOS, 7e Ann McIver McHoes Chapter Four, Page 3


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Understanding Operating Systems, 7th edition

d. Round robin (using a time quantum of 5, but ignore the time required for context
switching and natural wait)

Job Arrival CPU ANSWER ANSWER ANSWER ANSWER


Time Cycle FCFS SJN SRT RR
A 0 15 Start: 0 Start: 0 Start: 0 Start Time: 0
Finish: 15 Finish: 15 Finish: 28 Finish Time: 38
B 2 2 Start: 15, Start: 16 Start: 2 Start: 5
Finish: 17 Finish: 18 Finish: 4 Finish: 7
C 3 14 Start: 17, Start: 28 Start: 28 Start: 7
Finish: 31 Finish: 42 Finish: 42 Finish: 42

D 6 10 Start: 31, Start: 18 Start: 6 Start: 12


Finish: 41 Finish: 28 Finish: 17 Finish: 33
E 9 1 Start: 41, Start: 15 Start: 9 Start: 17
Finish: 42 Finish: 16 Finish: 10 Finish: 18

10. Using the same information given for Exercise 8, compute the turnaround time for
every job for each of the following scheduling algorithms (ignoring context switching
overhead times). <Answers are all shown in the table below>

a. FCFS

b. SJN

c. SRT

d. Round robin (using a time quantum of 5)

Job Arrival CPU ANSWER ANSWER ANSWER ANSWER


Time Cycle FCFS SJN SRT RR
A 0 15 Turnaroun Turnaround Turnaround Turnaround
d Time: 15 Time: 15: Time: 28 Time: 38
(15­0=15) (38­0=38)
B 2 2 turnaround: turnaround: turnaround: turnaround:
17 18­2 =16 2 7­2=5
C 3 14 turnaround: turnaround: turnaround: turnaround:

UOS, 7e Ann McIver McHoes Chapter Four, Page 4


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Understanding Operating Systems, 7th edition

31 42­3 = 39 39 42­3=39
D 6 10 turnaround: turnaround: turnaround: turnaround:
41 28­6=22 11 33­6=27
E 9 1 turnaround: turnaround: turnaround: turnaround:
42 16­9 = 7 1 18­9=9

11. Given the following information for a real­time system using EDF:

Job: A B C D E F

Arrival time: 0 0 1 1 3 6

Execution Time: 3 1 6 2 7 5

Deadline: 6 1 44 2 16 15

Time­before­ 6 1 43 1 13 9
deadline (6­ (1­ (44­ (2­ (16­3=13) (15­
(at arrival time) 0=6) 0=1) 1=43) 1=1) 6=9)

Compute the time­before­deadline for each incoming job. (ANS: shown above) Give
the order in which the six jobs will finish, and identify any jobs that fail to meet
their deadline. It may help to draw a timeline. ANS: Finishing order:
B, D, A, F, E, C. Job E misses its deadline of Time 16 by finishing at Time 18.
See timeline below:

Advanced Exercises

12. Consider this 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­

UOS, 7e Ann McIver McHoes Chapter Four, Page 5


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Understanding Operating Systems, 7th edition

fourth of its time quantum goes to a place one­fourth of the distance away from the
beginning of the queue. Explain the advantages and disadvantages of this scheduling
policy? ANS:
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.

Identify the user group that would find this most advantageous. ANS: The user group
finding this unusual queue activity advantageous are those running I/O jobs.
Examples include jobs that require printing, those making brief calculations, and
those that can quickly hand over the CPU so it can work on the next job waiting in the
queue.

13. When using a personal computer, it can be easy to determine when a job is caught in
an infinite loop or system­wide freeze. The typical solution to this problem is for the
user to manually intervene and terminate the offending job or in the worst case, all
jobs. 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, such as a task that is calculating the first
300,000 prime numbers.” ANS: 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.

14. Some guidelines for selecting the right time quantum were given in this chapter. As a
system designer, which guidelines do you prefer? Which would the average user
prefer? How would you know when you have chosen the best time quantum? What
factors would make this time quantum best from the system’s point of view? ANS:
Answers here should vary by student. Some would want to tune the system for speedy
responses. Others might need to optimize fixed resources, depending on the situation.
Look for an understanding of the choices that have been discussed in this chapter and
how those choices will impact users.

UOS, 7e Ann McIver McHoes Chapter Four, Page 6


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Understanding Operating Systems, 7th edition

15. Using the process state diagrams of Figure 4.2, explain why there’s no transition:

a. From the READY state to the WAITING state ANS: 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 ANS: 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.

Programming Exercises

16. Write a program that will simulate FCFS, SJN, SRT, and round robin scheduling
algorithms. For each algorithm, the program should compute waiting time and
turnaround time of every job as well as the average waiting time and average
turnaround time. The average values should be consolidated in a table for easy
comparison. You may use the following data to test your program. The time quantum
for round robin is 4 ms. (assume that the context switching time is 0).

Job Arrival Times CPU Cycle (in milliseconds)


A 0 16
B 3 2
C 5 11
D 9 6
E 10 1
F 12 9
G 14 4
H 16 14
I 17 1
J 19 8

UOS, 7e Ann McIver McHoes Chapter Four, Page 7


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Understanding Operating Systems, 7th edition

ANS: Exercises 16 is an outcome of the paper­and­pencil exercises done previously.


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.

17. Modify your program from Exercise 14, to generate a random job stream and change
the context switching time to 0.4 ms. Compare outputs from both runs and discuss
which would be the better policy. Describe any drastic changes encountered or a lack
of changes and explain why. ANS: Exercises 17 is an outcome of the paper­and­
pencil exercises done previously. 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.

UOS, 7e Ann McIver McHoes Chapter Four, Page 8


This study source was downloaded by 100000811044824 from CourseHero.com on 12-07-2022 16:21:10 GMT -06:00

https://www.coursehero.com/file/25814063/Chapter-4docx/
Powered by TCPDF (www.tcpdf.org)

You might also like