Reputation: 263
I watch a lot tutorials on youtube about RR scheduling and i had this question in exam but i don't know what i did wrong,the professor solution was different from my solution and i'm now confused.
Job | Arrival | Burst
P1 | 0 | 4
P2 | 2 | 5
P3 | 3 | 3
P4 | 8 | 4
QT = 1
Her answer was : P1,P1,P2,P3,P1,P2,P3,P1,P4,P2,P3,P4,P2,P4,P2,P4
My answer was : P1,P1,P2,P1,P3,P2,P1,P3,P2,P4,P3,P2,P4,P2,P4,P4
So which one is the correct answer and if it was her then why ?
Upvotes: 3
Views: 1703
Reputation: 13924
Highest priority goes to the new arrival, and the second priority is considered through FIFO in the waiting queue.
Queue
front P1 P2 P3 P4
-----------------------------------
0 P1 | [3]
1 P1 | [2] >>
2 P2 | 2 [4] >> <- P2 arrives
3 P3 | 2 4 [2] <- P3 arrives
4 P1 | [1] >> 4 2
5 P2 | 1 [3] >> 2
6 P3 | 1 3 [1]
7 P1 | [0] >> 3 1
8 P4 | 3 1 [3] <- P4 arrives. FIFO disrupted.
9 P2 | [2] >> 1 3 <- FIFO regained.
10 P3 | 2 [0] >> 3
11 P4 | 2 [2]
12 P2 | [1] >> 2
13 P4 | 1 [1]
14 P2 | [0] >> 1
15 P4 | [0]
Upvotes: 3
Reputation: 14866
Your teacher has a different approach. Whenever a new process arrives in the system, it has a higher priority than processes that finished their burst.
Upvotes: 1
Reputation: 1916
Both are correct !!!
I will say that your solution looks correct( but you are not considering a priority scheduling queue). But it depends how your professor is approaching. Following are the approaches:
Your Approach:
You are following normal queue operations. Only enque() and deque(). So using these 2, your approach is correct !!!
Your Professor's approach:
Whenever a new process is coming, he is putting it on the top of the queue. He is considering a priority queue instead where every new process has top priority.
So better if you discuss it with your professor. I would say you are not wrong !!!
Upvotes: 3
Reputation: 559
Her answer was correct.
You can approach the problem like this:
Hope this helps!
Upvotes: 2