3

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 ?

elias rizik
  • 263
  • 2
  • 11

4 Answers4

3

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 !!!

Shasha99
  • 1,746
  • 2
  • 16
  • 30
  • in most internet materials and YouTube videos they do it different way for example let's say we at time = 1 and now we have only P1 so we run it , after that comes P2 so they immediately add P1 after P2 before reaching time = 3 , so it become like that P1,P1,P2,P1 so now i'm confused and what exactly you mean by paused ? – elias rizik Oct 25 '16 at 17:55
  • Ok, wait for a minute.I understood your problem. – Shasha99 Oct 25 '16 at 18:03
  • You should definitely discuss it with your professor. He is also correct given that he told you about the priority queue he is using. – Shasha99 Oct 25 '16 at 18:31
3

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]
Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79
2

Her answer was correct.

You can approach the problem like this:

  1. Open a new notebook page
  2. Number each line 0-15 (16 total lines; SUM(Burst) column)
  3. Start by writing the job on the line it arrives on (P1 on line numbered 0, P2 on line numbered 2, P3 on line numbered 3, P4 on line numbered 8)
  4. Now you know each job can only occur after that line.
  5. Next, start filling in the rest of the lines in sequential order where the lines have no jobs defined and where the jobs have appeared less than the number of Bursts defined for that job.

Hope this helps!

brad
  • 529
  • 4
  • 5
  • yeah that was helpful it gave me the right answer but i didn't understand why :P – elias rizik Oct 25 '16 at 17:57
  • As the question is defined, each job can execute N times -- where N is the number of Bursts. – brad Oct 25 '16 at 18:05
  • Once we fill out each line where the job arrives, each job has 1 less burst. As time increases and the jobs are available to be scheduled, the job gets added to the queue. – brad Oct 25 '16 at 18:08
  • As you continue, the jobs are taken from the queue and executed in the order in which they were received. This continues until the job has executed for the defined amount of bursts – brad Oct 25 '16 at 18:11
1

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.

Tony Tannous
  • 14,154
  • 10
  • 50
  • 86