Non-Preemptive Shortest Job First Scheduling


Shortest Job First is another type of scheduling technique in which the process with the shortest burst time is given to CPU first for execution. SJF scheduling is a non - preemptive scheduling technique.

Characteristics of SJF algorithm

  • The average waiting time by using SJF is less than FCFS.
  • Since processes with shorter burst time is executed first hence the turnaround time is also short by using SJF.
  • SJF gives an improved output by selecting a shorter job first to execute.
  • This scheduling technique is useful for batch-time processing, where waiting for jobs to complete is not critical.
Drawbacks of Non-Preemptive Shortest Job First Scheduling

One major drawback of SJF non-preemptive version is:
If all processes arrive in ready queue at different time, then there might be a chance that a process with short burst time have to wait for the current process's execution to finish. This is because when a process with shorter burst time comes then the existing job is stopped to execute and the shorter process is given to CPU.
This can lead to a serious problem also known as Starvation that a process is never getting executed because every time a process with shorter burst time comes and obstructs this process to get CPU.
To resolve this problem we have a concept of Ageing. In ageing we assign a priority to each process and this priority is increased as a process is starved more and more and then after some time interval
we check the priority of the processes and the process with highest priority is given CPU.







Numerical:

-->Given the processes below draw a gantt chart for the execution if processes using SJF and find waiting time as well as turn around time for each process.

Non-Preemptive Shortest Job First Scheduling

P1 is the first process to arrive in the ready queue with arrival time of 0 so it will be executed first for complete 4ms.
Now, the process with the shortest burst time will be executed first. Since P3 has the shortest burst time thus it will be executed for 1ms.
The next process with the shortest burst time is P4 which will execute for 2ms.
The next process with the shortest burst time is P2 so it will execute for 3ms.
Now, the last process P5 will be executed for 6ms.
The gantt chart for the table is:

Non-Preemptive Shortest Job First Scheduling

Waiting Time for each Process

Waiting time is computed by the formula starting execution time - arrival time of a process.
Process                                  Starting execution time - arrival time                          Waiting time
P1                                                            0 - 0                                                                  0
P2                                                            7 - 1                                                                  6
P3                                                            4 - 2                                                                  2
P4                                                            5 - 3                                                                  2
P5                                                           10 - 4                                                                 6







Turn around Time for each Process

Turn around time is computed by the formula completion time - arrival time of a process.
Process                                  Completion time - arrival time                          Waiting time
P1                                                            4 - 0                                                                  4
P2                                                          10 - 1                                                                  9
P3                                                            5 - 2                                                                  3
P4                                                            7 - 3                                                                  4
P5                                                          16 - 4                                                                 12

Implementation of SJF in C++


OUTPUT:


Non-Preemptive Shortest Job First Scheduling


Here you can follow me if you are interested:







3 Comments

  1. If have 2 process the arrival is 0,the process cannot choose the lower burst time,how to solve it

    ReplyDelete
    Replies
    1. 2 processes can never have same arrival time. There will always be some time difference in the arrival of 2 process (in milliseconds). So the process which has lower arrival time will be selected for execution first.

      Delete
  2. Shortest Job First Algorithm Example 2 and Example 3 | SJF Non Preemption Algorithm with examples computer4quant
    https://youtu.be/9B3Xu7Y3t7c

    ReplyDelete
Post a Comment
Previous Post Next Post