916 views
0 votes
0 votes
Consider we have a cpu whose processes are scheduled using premptive priority scheduling algorithm, suppose a process of higher priority than the currently running process arrives in the ready queue, according to the algorithm the running process must be prempted, who actually does this job of interrupting the running process?

3 Answers

Best answer
4 votes
4 votes

In this preemptive priority scheduling algorithm, suppose a process with priority p is currently being executed by the cpu. 


Now when a new process arrives in the system and enters the ready queue, this algorithm selects this process for execution by preempting the current process if the new process has priority greater than p. Here many question arises.

How this algorithm execute? Does this algorithm executes in user mode or kernel mode?


One point to remember is that : operating system is interrupt driven. And if any kernel routine is run in user mode, then it results in a trap to operating system and os changes the mode to kernel mode. And any routine/ algorithm run by operating system is a kernel routine.


Here preemptive priority scheduling algorithm is short term scheduling algorithm. When a new process enters the system, an interrupt occurs. This interrupt causes the operating system to save the current task and run a kernel routine. Here the current task is the current process being executed by cpu and kernel routine is scheduling algorithm. This is context switch. Thus the state of current process is saved in its process control block and put back in ready queue and scheduler( kernel routine ) is executed next in kernel mode. 

Don't think that this is done by dispatcher. Dispatcher is another kernel routine which is invoked by short term scheduler. This context switch is done as a result of interrupt to os. 


Then this scheduler executes and chooses the process with highest priority. There are two cases:

1. New process is selected. Then this process starts executing next.

2. Previous process is again selected. Then this process resumes execution from its saved context.

How does process starts execution?

After selecting a process according to an algorithm, short term scheduler invokes the dispatcher. Dispatcher is responsible in changing the ready state of new process to run state and start executing by the cpu.

selected by
0 votes
0 votes
Short term scheduler will select the process and dispatcher will load the selected process into the CPU
0 votes
0 votes
Dispatcher does this job. It is notified by short term scheduler through a system call. The short term scheduler checks for new or preemptable processes time to time. This it will learn which process to be preempted.

Related questions

0 votes
0 votes
0 answers
2
1 votes
1 votes
1 answer
3
Syedarshadali asked Oct 22, 2017
419 views
If inefficiency of scheduling algorithm is $\frac{Burst Time wasted}{Total Burst Time} X 100$Why do we have to multiply with 100?