Search code examples
round-robin

priority based round robin algorithm in operating system: is this preempted?


in priority based round robin algorithm, when higher priority process (let's say P1) is arrived during lower priority process (P2) is processing, P2 must be preempted and P1 is processed instead. right?

then what if, after specific time quantum (ex. 10ms)

  • is P1 keep processed? (since P1 has a higher priority)

  • or P1 is preempted and scheduler dispatch P2 (because in round robin, after the time quantum, job must be switched)

i think the second thought is right, but book is confusing me. (operating system concepts international ver. exercise 5.8)

thanks a lot


Solution

  • This depends. How this is implemented in normal Round Robin, where there is no priority then we should preempt to P2. But this has priority to it, which we do preempt, but to whatever process happens to have the next highest priority (to keep things simple).

    Let's assume that it is implemented in this way:

    • Processes are only preempted via the time slice of the Round Robin
    • Priority will simply be based on the order the processes are executed in RR (to avoid starvation problems)

    This may be different than what your book has, for example it may increase the priority of processes based on how long they have been in the queue, then preempt to the current highest (in which may be the same process). But the way I defined above it more focus on the Round Robin fair sharing. In this case P1 is preempted and we move to P2, the same way normal RR works.

    But lets move into a better example say we have P1 (priority = high), P2 (priority = low), and P3 (priority = med). And then enter the queue in the order of: P1, P2, P3. Then from how I defined Priority RR will do this:

    P1 -> [high] Notice the priority simply changes the ordering
    P3 -> [med]  But each still has the same time slice.
    P2 -> [low]
    P1
    P3
    P2
    

    Each with a N time slice. Surely yes it does not seem Priority is playing a big factor here, RR is more focus on. But as the number of process in the ready queue are large (and perhaps the time slice is large), then it will play a bit of a bigger factor.