0% found this document useful (0 votes)
18 views

HW 2

homework in case practice is needed.

Uploaded by

absoluteglizzy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

HW 2

homework in case practice is needed.

Uploaded by

absoluteglizzy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

COEN 346 OPERATING SYSTEMS

Theoretical Assignment # 2
Scheduling
1) Assume that the following processes are the only processes in a computer system and that
there are no input/output requests from all the given processes. Answer the following
questions for each process's following arrival time and CPU burst time (also called service
time).

Process Arrival Time CPU Burst Time

P1 0 20
P2 3 7
P3 5 2
P4 7 3

a) Draw the Gantt chart and compute the throughput, average waiting time and average
turnaround time for the following CPU scheduling algorithms. Here the waiting time of a
process includes all the time it spends in the ready list.
i. (15pts) First Come First Service (FCFS).
ii. (15pts) Preemptive Shortest Job Next (Shortest Remaining Job Next).
iii. (20pts) Round-Robin with a time quantum of 4 (Assume that new processes will be
inserted at the end of the ready list).
a) (10pts) According to your results, which scheduling algorithm in (a) gives the shortest
average waiting time? Is that consistent with your theoretical prediction? Justify your
answer.
CPU utilization
[15 points] Suppose that the context switch takes 1 unit of time. What is the CPU utilization of
each algorithm in the above example?

Scheduler Implementation
[25 points] You are writing the code for the Round-Robin scheduler of an Operating System.
Complete the code as instructed. You can write pseudo-code. The focus is on the correctness of
the algorithm and chosen data structures rather than on the syntax of a specific language.

a) Define a process structure (PCB) with process id, arrival time,


remaining time, burst_time, and priority. These attributes will
help the scheduler in its decisions. Consider all CPU bursts of
the process take the same time and the remaining time is the
global time to terminate the process.
b) Define the time_quantum variable, that will save the time each
process is allowed to run. Define the current_time_quantum
variable to save the time remaining for the current time quantum.
COEN 346 OPERATING SYSTEMS
Define the current_process variable, which represents the
currently running process.
c) Define the data structure (list, queue, hashtable, etc) that you
will use to save the processes ready to run.
d) Define the tick method. This method simulates one unit of time.
Consider what happens to the currently running process and the
current_time_quantum. Consider all situations: process finished,
process current burst finished, time quantum finished.
e) Define the context_switch method, which will switch the currently
running process for the next one (you don’t need to do the saving
of context, you can just add a comment of when this will happen).

You might also like