SRTF with Processes contains CPU and IO Time

 

Till now, we were considering the CPU bound jobs only. However, the process might need some IO operation or some resource to complete its execution. In this Example, we are considering, the IO bound processes.

In the Example, there are four jobs with process ID P1, P2, P3 and P4 are available. Their Arrival Time, and the CPU Burst time are given in the table below.

Process Id

Arrival Time

(Burst Time, IO Burst Time, Burst Time)

1

0

(3,2,2)

2

0

(1,3,1)

3

3

(3,1,2)

4

6

(5,4,5)

 

GANTT Chart Preparation

At time 0, the process P1 and P2 arrives. Since the algorithm we are using is SRTF hence, the process with the shortest burst time will be scheduled on the CPU. In this case, it is P2.



From time 0 to time 1, P2 will be in running state.



P2 also needs some IO time in order to complete its execution. After 1 unit of execution, P2 will change its state from running to waiting. The processor becomes free to execute other jobs. Since No other process is available at this point of time other than P1 so P1 will get executed.

The following diagram illustrates the processes and states at Time 1. The process P2 went to waiting state and the CPU becomes idol at this time.



From time 1 to 3, since P2 is being in waiting state, and no other process is available in ready queue, hence the only available process P1 will be executed in this period of time.



At time 3, the process P3 arrived with the total CPU burst time of 5 units. Since the remaining burst time of P1 is lesser then P3 hence CPU will continue its execution.



Hence, P1 will remain in the running state from time 3 to time 4.



Since P1 is an IO bound process. At time unit 4, it will change its state from running to waiting. Processor becomes free for the execution of other jobs. Since P2 also becomes available at time 4 because it has completed the IO operation and now it needs another 1 unit of CPU burst time. P3 is also available and requires 5 units of total CPU burst time.



The process with the least remaining CPU burst time among the available processes will get executed. In our case, such process is P2 which requires 1 unit of burst time hence it will be given the CPU.



At time 5, P2 is finished. P1 is still in waiting state. At this point of time, the only available process is P3, hence it will be given the CPU.



From Time 5 to time 6, P3 will be in the running state; meanwhile, P1 will still be in waiting state.




At time 6, the Process P4 arrives in the ready queue. The P1 has also done with the IO and becomes available for the execution. P3 is not yet finished and still needs another 2 unit of CPU burst time.

From time 6 to time 8, the reaming CPU burst time of Process P3 is least among the available processes, hence P3 will be given the CPU.



P3 needs some IO operation in order to complete its execution. At time 8, P3 will change its state from running to waiting. The CPU becomes free to execute the other processes. Process P4 and P1 are available out of which, the process with the least remaining burst time will get executed.



From time 8 to time 9, the process P1 will get executed.



At time 9, the IO of process P3 is finished and it will now be available in the ready state along with P4 which is already waiting there for its turn. In order to complete its execution, it needs another 2 unit of burst time. P1 is in running state at this point of the time while no process is present in the waiting state.




from time 9 to 10 , the process P1 will get executed since its remaining CPU burst time is lesser then the processes P4 and P3 available in the ready queue.



At time 10, execution of P1 is finished, and now the CPU becomes idol. The process with the lesser CPU burst time among the ready processes will get the CPU turn.

From time 10 to 12, the process P3 will get executed till its completion because of the fact that its remaining CPU burst time is the between the two available processes. It needs 2 units of more CPU burst time, since No other process will be arrived in the ready state hence No preemption will be done and it will be executed till the completion.



At time 12, the process P3 will get completed, since there is only one process P4 available in the ready state hence P4 will be given the CPU.



P4 needs 5 units of CPU burst time before IO, hence it will be executed till time 17 (for 5 units) and then it will change its state from running to waiting.

At time 17, the Process P4 changes its state from running to waiting. Since this is the only process in the system hence the CPU will remain idol until P4 becomes available again.



At time 21, P4 will be done with the IO operation and becomes available in the ready state.



From time 21, the process P4 will get scheduled. Since No other process is in ready queue hence the processor don't have any choice. It will be executed till completion.



Final Gantt chart:

Process Id

Arrival Time

Total CPU Burst Time

Completion Time

Turn Around Time

Waiting Time

1

0

5

10

10

5

2

0

2

5

5

3

3

3

5

12

9

4

4

6

10

26

20

10

               Average waiting Time = (5+3+4+10)/4 = 22/4 units