Shortest Job First Algorithm C Program

By | September 5, 2016

Let us learn how to implement the shortest job first scheduling algorithm in C programming with its explanation, output, advantages, disadvantages and much more.

What is Shortest Job First Algorithm?

The shortest job first scheduling algorithm is a very popular job scheduling algorithm in operating systems. This algorithm is designed to overcome the shortcomings of the FCFS algorithm.

The SJF algorithm is also popularly known by the following names:

  • Shortest Job Next algorithm
  • Shortest Remaining Time First algorithm
  • Shortest Process Next algorithm

Initially, the job queue contains multiple processes for execution. According to the SJF algorithm, the processes are compared with each other and the process that has the shortest burst time (execution time) gets executed first.

The remaining processes are also executed in the order of their burst times. If there are two or more processes having the same burst time, the processes are executed in the order of their arrival.

This is a non-preemptive algorithm which means that the CPU cannot leave a process in execution and start execution of another process.

Once the CPU starts execution of a job, it has to complete it successfully and then it can move to any other process in the job queue.

Note: This SJF non preemptive scheduling program in c with output does not consider arrival time of the processes entering the job queue.


  • The response time of the processes is better.
  • The throughput time is much better as the time taken for execution is much less.
  • The overall performance of the system is efficient.


  • The execution time of all the processes in the job queue must be known in advance to apply the algorithm efficiently to all the jobs.
  • The processes with larger execution time will have a higher waiting time, and this may lead to starvation.

Note: This shortest job first scheduling program in c language is compiled with GNU GCC compiler using Linux terminal on Linux Ubuntu operating system.

C Program For Non Preemptive Shortest Job First Scheduling Algorithm



shortest job first scheduling program in C Programming with Preemptive Scheduling Program in OS

If you have any doubts about the implementation of the shortest job first scheduling program in c language, let us know about it in the comment section. Find more about it on Wikipedia.

CPU Scheduling Algorithms
FCFS Algorithm C Program C Program
SCAN Disk Algorithm C Program
Preemptive Shortest Job First Algorithm C Program
Round Robin Algorithm C Program
Multi-Level Feedback Queue Algorithm C Program
Preemptive Priority Algorithm C Program
Priority Scheduling Algorithm C Program
Shortest Seek Time First Algorithm C Program
C SCAN Scheduling Algorithm C Program

12 thoughts on “Shortest Job First Algorithm C Program

  1. Anil Tandan

    Does the same code work in Windows 7 platform too? I am not using Linux ubuntu actually!

  2. Ajay Kadam

    This is the best working code that I found for SJF Algorithm. Thank you so much CodingAlpha

  3. Vedant Mishra

    I think a Preemptive SJF Algorithm will be more efficient than a Non Preemptive Algorithm. It will help to increase the overall performance of the CPU.

  4. Vikas Mishra

    This SJF Scheduling Algorithm in Operating System C Program is really easy to understand. Thanks for this one.

  5. Anonymous

    can you provide non preemptive shortest job first with arrival time in c?


Let's Discuss