If a job is being processed, wouldn't it have the smallest time till completion, since it will just end up as the head of the Ready-to-Run Queue, when it is preempted?
So is this just a repeating cycle till a job has reached completion, with overheads?
Wouldn't longer processes be neglected (just like SJF)?
Thanks
No, a job being processed doesn't necessarily have the shortest remaining time. SRTF checks if there's a process in the ready queue which has less burst time to complete to do the preemption. Let's say you have p1,p2 and p3. p1 has a total burst of 15 and arrives at time 0, p2 has a burst of 10 and arrives at time 3, p3 has a burst of 1 and arrives at time 4.
The execution with SRTF would be:
p1 -> from 0 to 3, remaining burst -> p1 = 12
at 3, arrives p2, p2 burst < p1 remaining burst, so p2 gets the cpu
p2 -> from 3 to 4, remaining burst -> p1=12,p2 = 9
at 4 arrives p3, p3 burst < p2 remaining burst < p1 remaining burst, so p3 gets the cpu
p3-> from 4 to 5, remaining burst -> p2=9,p1=12
p2-> from 5 to 14, remaining burst -> p1=12
p1-> from 14 to 26, end