Javatpoint Logo
Javatpoint Logo

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.


os SRTF with Processes contains CPU and IO Time
os SRTF with Processes contains CPU and IO Time1

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


os SRTF with Processes contains CPU and IO Time 2

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.


os SRTF with Processes contains CPU and IO Time 3

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.


os SRTF with Processes contains CPU and IO Time 4
os SRTF with Processes contains CPU and IO Time 5

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.


os SRTF with Processes contains CPU and IO Time 6

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


os SRTF with Processes contains CPU and IO Time 7
os SRTF with Processes contains CPU and IO Time 8

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.


os SRTF with Processes contains CPU and IO Time 9

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.


os SRTF with Processes contains CPU and IO Time 10
os SRTF with Processes contains CPU and IO Time 11

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.


os SRTF with Processes contains CPU and IO Time 12

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


os SRTF with Processes contains CPU and IO Time 13
os SRTF with Processes contains CPU and IO Time 14
os SRTF with Processes contains CPU and IO Time 15

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.


os SRTF with Processes contains CPU and IO Time 16
os SRTF with Processes contains CPU and IO Time 17

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.


os SRTF with Processes contains CPU and IO Time 18

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


os SRTF with Processes contains CPU and IO Time 19
os SRTF with Processes contains CPU and IO Time 20

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.


os SRTF with Processes contains CPU and IO Time 21
os SRTF with Processes contains CPU and IO Time 22

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.

os SRTF with Processes contains CPU and IO Time 23
os SRTF with Processes contains CPU and IO Time 24

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.


os SRTF with Processes contains CPU and IO Time 25
os SRTF with Processes contains CPU and IO Time 26

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.


os SRTF with Processes contains CPU and IO Time 27

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.

os SRTF with Processes contains CPU and IO Time 28

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.


os SRTF with Processes contains CPU and IO Time 29
os SRTF with Processes contains CPU and IO Time 30

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


os SRTF with Processes contains CPU and IO Time 31

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.


os SRTF with Processes contains CPU and IO Time 32

Final Gantt chart:

os SRTF with Processes contains CPU and IO Time 33
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






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA