614 views
0 votes
0 votes
I am reading Galvin O.S. and came across this line 2. When a process switches from the running state to the ready state (for example, when an interrupt occurs), scheduling is not needed I but If a process has moved to ready queue scheduling is definitely needed. Where am I wrong?           O.S. Galvin Edition 9th Page 264

2 Answers

Best answer
7 votes
7 votes

Brief introduction on process execution:  

For a process say Po,being in a ready queue & being in a ready state is two different thing.If some processes are in ready queue,it means that these processes are ready for execution in cpu.Now since at a time only one process can be executed in cpu(assuming single cpu),it is scheduler(short-term)'s job to decide which process it should select from Ready Queue depending upon certain scheduling algorithms like FCFS,SJF,SRJF,RR etc.So once a particular process is selected for execution,it is put into ready state by scheduler.Now scheduler calls dispatcher to put this process in execution on cpu but dispatcher can't directly put into cpu because some other process (say P1) is running on cpu.So dispatcher first save PCB of current running process P1( which involves lot of tasks like saving registers content,PC,next instruction to execute etc which are also called context-switching overhead)

i.e.  dispatcher first saves context of current running process P1 & then put it back into Ready Queue or Blocked Queue depending upon cause of interruption(.e.g.if IO interrupt occurs,it goes to Blocked/Waiting Queue and if say time-quantum expires,it goes to ready-queue.) Now dispatcher puts the process Pon cpu for execution.

Now if a running process is interrupted ,this process goes to ready-state not in ready-queue because this process is already scheduled for execution but it got interrupted.So dispatcher will save next instruction to be executed and interrupt service routine(ISR) will start executing on cpu.On completion of this ISR,earlier running process resumes its execution.So no scheduling is required.

But if say process got preempted because of a reason(say higher priority process or shortest-job process arrive in ready queue),then it is put into ready-queue.So now again problem comes like which one will be next for execution.So depending on scheduling algorithm,one of the process(need not be same as earlier process)  gets scheduled by scheduler(short-term) .so in this case scheduling is required.

selected by
1 votes
1 votes
The job of a scheduler is to bring process from Ready state to running state . the short term scheduler is the one which select which process will be brought from Ready queue to running state,However it just decide which process but the actual job is done by Dispatcher .

as soon as interupt occur Or quantum expires , the dispatcher is woke up and new process is put to running . which eventually move the previous running to ready . So no scheduling is required here ,

Related questions