- Information
- AI Chat
8. Quiz Problem Example
Operating Systems Principles (CSCI 340)
Queens College CUNY
Recommended for you
Preview text
Quiz Problem
Let q be = Quantum Time Pi be = Process i where ( i =0,1,2, ... ) WT be = Waiting Time TAT be = Turnaround Time
AT be = Arrival Time CT be = Completion Time BT be = Burst Time RT be = Remaining Burst Time
Draw Gantt Chart for each of the following scheduling algorithm : Shortest Remaining Time (SRT) algorithm Round Robin (RR) algorithm with q = 1 Multilevel Feedback Scheduling where : 1 st Queue is RR algorithm with q = 1 2 nd Queue is RR algorithm with q = 2 3 rd Queue is FCFS algorithm
P AT BT
P 0 0 4
P 1 1 7
P 2 4 3
P 3 6 8
Step 0: Start with an empty Gantt Chart.
t = 0246810121416182022 RT P 0 4
P 1 7
P 2 3
P 3 8
SRT Algorithm Made By: asifroni673@gmail / asif@qmail.cuny Step 1: When t = 0 , P 0 arrives and is the only process available. Since this algorithm is preemptive, this process can run and be paused at a given time from the arrival of another process. So P 0 will execute partial burst time and will continue to be executed at another time. For now, P 0 will execute for 1 ms because another process, P 1 , arrives when t = 1. And P 0 has remaining burst time of 3 ms.
t = 0246810121416182022 RT P 0 0 4 3
P 1 7
P 2 3
P 3 8
Step 2: When t = 1 , P 1 arrives and two processes ( P 0 , P 1 ) are available. Following SRT algorithm, the CPU will compare the available processes and execute one process
with the minimum burst time : ( P 0 = 3 )<( P 1 = 7 ), P 0 will be executed. By then, P 0
has completed its service time.
t = 0246810121416182022 RT P 0 0 0 3 0
P 1 7
P 2 3
P 3 8
Step 3: When t = 2 , P 2 arrives and two processes ( P 1 , P 2 ) are available. Following SRT algorithm, the CPU will compare the available processes and execute one process
with the minimum burst time : ( P 1 = 7 )>( P 2 = 3 ), P 2 will be executed. But because
this algorithm is preemptive, P 2 will run partial burst time of 2 ms due to the arrival of P 3 at t = 6 , P 2 will be paused, and P 2 will resume the remaining burst time of 1 ms at another time.
t = 0246810121416182022 RT P 0 0 0 0
P 1 7
Made By: asifroni673@gmail / asif@qmail.cuny
Complete Gantt Chart ~ SRT Algorithm t = 0246810121416182022
P 0 0 0
P 1 1
P 2 2 2
P 3 3
P CT TAT WT
P 0 4 4 0
P 1 14 13 6
P 2 7 3 0
P 3 22 16 8
RR Algorithm ( q = 1 ) Made By: asifroni673@gmail / asif@qmail.cuny
Let there be a Data Structure Queue with type Pi called PQueue.
If there is an arrival of new process, the CPU will enqueue the new process first as it is high priority. Otherwise, enqueue other available process that has remaining burst time.
PQueue enqueue→ ⋯ dequeue→
If the CPU dequeue from PQueue , then a process is available for runtime execution. Step 1: When t = 0 , P 0 arrives and is the only process available. Following RR algorithm, the new process is P 0 and there are no other available processes. P 0 is enqueued. PQueue P 0
Then the CPU will dequeue a process, P 0 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 0
t = 0246810121416182022 RT
P 0 0
P 1 7
P 2 3
P 3 8
Step 2: When t = 1 , P 1 arrives and one process ( P 0 ) is available. Following RR algorithm, since the new process is P 1 and the other available process is P 0 , then P 1 and P 0 are enqueued orderly. PQueue P 0 P 1
Then the CPU will dequeue a process, P 1 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 0 P 1
t = 0246810121416182022 RT P 0 0 3
P 1 1 7 6
P 2 3
P 3 8
Step 3: When t = 2 , only one process ( P 1 ) is available. Following RR algorithm, since there is no arrival of new process, P 1 is enqueued. PQueue P 1 P 0
Then the CPU will dequeue a process, P 0 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 1 P 0
t = 0246810121416182022 RT P 0 0 0 3 2
P 1 1 6
P 2 3
8
P 2
P 3 8
Step 6: When t = 5 , only one process ( P 0 ) is available. Following RR algorithm, since there is no arrival of new process, P 0 is enqueued. PQueue P 0 P 1 P 2
Then the CPU will dequeue a process, P 2 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 0 P 1 P 2
t = 0246810121416182022 RT P 0 0 0 0 1
P 1 1 1 5
P 2 2 3 2
P 3 8
Step 7: When t = 6 , P 3 arrives and one process ( P 2 ) is available. Following RR algorithm, since the new process is P 3 and the other available process is P 2 , then P 3 and P 2 are enqueued orderly. PQueue P 2 P 3 P 0 P 1
Then the CPU will dequeue a process, P 1 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 2 P 3 P 0 P 1
t = 0246810121416182022 RT P 0 0 0 0 1
P 1 1 1 1
P 2 2 2
P 3 8
Step 8: When t = 7 , only one process ( P 1 ) is available. Following RR algorithm, since there is no arrival of new process, then P 1 is enqueued. PQueue P 1 P 2 P 3 P 0
Then the CPU will dequeue a process, P 0 , for the runtime execution. And since its’ remaining burst time is equal to 1 ms , P 0 completes its duration. PQueue P 1 P 2 P 3 P 0
t = 0246810121416182022 RT P 0 0 0 0 0 1 0
P 1 1 1 1 4
P 2 2 2
P 3 8
Step 9: When t = 8 , P 0 has complete its duration. Following RR algorithm, since there are no arrival of new process and no other available process, nothing will be enqueued. PQueue P 1 P 2 P 3
Then the CPU will dequeue a process, P 3 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 1 P 2 P 3
t = 0246810121416182022 RT P 0 0 0 0 0 0
P 1 1 1 1 4
P 0 0 0 0 0
P 1 1 1 1 1 4 3
P 2 2 2 1
P 3 3 7
Step 12: When t = 11 , only one process ( P 1 ) is available. Following RR algorithm, since there is no arrival of new process, P 1 is enqueued.
PQueue P 1 P 2 P 3
Then the CPU will dequeue a process, P 3 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 1 P 2 P 3
t = 0246810121416182022 RT P 0 0 0 0 0 0
P 1 1 1 1 1 3
P 2 2 2 1
P 3 3 3 7 6
Step 13: When t = 12 , only one process ( P 3 ) is available. Following RR algorithm, since there is no arrival of new process, then P 3 is enqueued.
PQueue P 3 P 1 P 2
Then the CPU will dequeue a process, P 2 , for the runtime execution. And since its’ remaining burst time is equal to 1 ms , P 2 completes its duration.
PQueue P 3 P 1 P 2
t = 0246810121416182022 RT
P 0 0 0 0 0
P 1 1 1 1 1 3
P 2 2 2 2 1 0
P 3 3 3 6
Step 14: When t = 13 , P 2 has complete its duration. Following RR algorithm, since there are no arrival of new process and no other available process, nothing will be enqueued. PQueue P 3 P 1
Then the CPU will dequeue a process, P 1 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. PQueue P 3 P 1
t = 0246810121416182022 RT P 0 0 0 0 0 0
P 1 1 1 1 1 1 3 2
P 2 2 2 2 0
P 3 3 3 6
Step 15: When t = 14 , only one process ( P 1 ) is available. Following RR algorithm, since there is no arrival of new process, P 1 is enqueued. PQueue P 1 P 3
Then the CPU will dequeue a process, P 3 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time.
PQueue P 1 P 3
t = 0246810121416182022 RT P 0 0 0 0 0 0
P 1 1 1 1 1 1 1 1
P 2 2 2 2 0
P 3 3 3 3 3 5 4
Step 18: When t = 15 , only one process ( P 3 ) is available. Following RR algorithm, since there is no arrival of new process, P 3 is enqueued.
PQueue P 3 P 1
Then the CPU will dequeue a process, P 1 , for the runtime execution. And since its’ remaining burst time is equal to 1 ms , P 1 completes its duration.
PQueue P 3 P 1
t = 0246810121416182022 RT P 0 0 0 0 0 0
P 1 1 1 1 1 1 1 1 1 0
P 2 2 2 2 0
P 3 3 3 3 3 4
Step 19: When t = 18 , P 1 has complete its duration. Following RR algorithm, since there are no arrival of new process and no other available process, nothing will be enqueued. PQueue P 3
Then the CPU will dequeue a process, P 3 , for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time.
PQueue P 3
t = 0246810121416182022 RT P 0 0 0 0 0 0
P 1 1 1 1 1 1 1 1 0
P 2 2 2 2 0
P 3 3 3 3 3 3 4 3
Step 20: When t = 19 , P 3 is the only process available left. Therefore, the CPU will enqueue P 3.
PQueue P 3
Then the CPU will dequeue P 3 for the runtime execution. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms before being paused and resume to complete the remaining duration at another time. This step will repeat for the remainder of P 3 ’s remaining service. PQueue P 3
t = 0246810121416182022 RT P 0 0 0 0 0 0
P 1 1 1 1 1 1 1 1 0
P 2 2 2 2 0
P 3 3 3 3 3 3 3 3 3 3 0
Complete Gantt Chart ~ RR Algorithm t = 0246810121416182022
P 0 0 0 0 0
enqueue
Q 1 complete
dequeue from Q 1
Q 2 complete
dequeue from Q 2
Q 3 complete
Step 1: When t = 0 , P 0 arrives and is the only process available. Following MLFQ algorithm, P 0 is the new process and is allocated to the highest priority, Q 1. The CPU selects Q 1 and performs Round – Robin (RR) algorithm with q = 1.
MLFQScheduler
enqueue
Q 1 P 0 complete
The CPU will selectively pick the process to be executed from Q 1. By dequeuing, P 0 will be the next process to be executed. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms , q = 1. Then in MLFQ algorithm, P 0 is paused and demoted to next queue. It is allocated to Q 2 and will resume to complete the remaining duration at another time since P 0 has remaining burst time of 3 ms.
MLFQScheduler
enqueue
Q 1 P 0 complete
Q 2 P 0 complete
dequeue to Q 3
t = 0246810121416182022 RT P 0 0 4 3
P 1 7
P 2 3
P 3 8
Step 2: When t = 1 , P 1 arrives and is the only process available. Following MLFQ algorithm, P 1 is the new process and is allocated to the highest priority, Q 1. The CPU selects Q 1 and performs Round – Robin (RR) algorithm with q = 1.
MLFQScheduler enqueue
Q 1 P 1 complete
The CPU will selectively pick the process to be executed from Q 1. By dequeuing, P 1 will be the next process to be executed. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms , q = 1. Then in MLFQ algorithm, P 1 is paused and demoted to next queue. It is allocated to Q 2 and will resume to complete the remaining duration at another time since P 1 has remaining burst time of 6 ms.
MLFQScheduler enqueue
Q 2 P 1 P 0 complete
Q 3 P 0 complete
t = 0246810121416182022 RT P 0 0 0 3 1
P 1 1 6
P 2 3
P 3 8
Step 4: When t = 4 , P 2 arrives and is the only process available. Following MLFQ algorithm, P 2 is the new process and is allocated to the highest priority, Q 1. The CPU selects Q 1 and performs Round – Robin (RR) algorithm with q = 1.
MLFQScheduler enqueue
Q 1 P 2 complete
The CPU will selectively pick the process to be executed from Q 1. By dequeuing, P 2 will be the next process to be executed. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 1 ms , q = 1. Then in MLFQ algorithm, P 2 is paused and demoted to next queue. It is allocated to Q 2 and will resume to complete the remaining duration at another time since P 2 has remaining burst time of 2 ms.
MLFQScheduler enqueue
Q 1 P 2 complete
Q 2 P 2 P 1 complete
dequeue to Q 3
t = 0246810121416182022 RT P 0 0 0 1
P 1 1 6
P 2 2 3 2
P 3 8
Step 5: When t = 5 , there is no arrival of new process available and two processes ( P 1 , P 2 ) are in Q 2 and one process ( P 0 ) is in Q 3. Following MLFQ algorithm, the CPU selects Q 2 and performs Round – Robin (RR) algorithm with q = 2.
MLFQScheduler dequeue from Q 1
Q 2 P 2 P 1 complete
The CPU will selectively pick the process to be executed from Q 2. By dequeuing, P 1 will be the next process to be executed. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 2 ms , q = 2. Then in MLFQ algorithm, P 1 is paused and demoted to next queue. It is allocated to Q 3 and will resume to complete the remaining duration at another time since P 1 has remaining burst time of 4 ms.
MLFQScheduler dequeue from Q 1
8. Quiz Problem Example
Course: Operating Systems Principles (CSCI 340)
University: Queens College CUNY
- Discover more from: