ANONYMOUS wrote:
> Hi,
>
> I have a working solution but I've just confused myself with why it works.
>
> Could someone explain, for a simple command file as below with a time quantum of 5
> #
> shortsleep
> 5usecs exit
> #
>
> Why the output is as below? Particularly, after further thought I've confused myself as to why this process ever makes it from running back to ready. The process completes its computation of 5usecs within the time quantum allowance so wouldn't it just exit, making the total time since reboot 10?
After the process has spent 5usecs on the CPU performing some computation, its time-quantum expires and it's removed from the CPU.
It does not "look into the future" to see what system-call is coming next, and then perform it if it happens to be an
exit
.
> Also if the transition from running to exit takes 0usecs, why does the time since reboot advance to 26usecs in the sample solution. Should it not be 25?
The transition takes 5usecs 21,22,23,24,25 - t=25 is part of the transitioning time. After those 5usecs, at t=26, the process resumes its execution with
exit
. The transition for the
exit
does take 0secs - the clock has not advanced to 27...