Javatpoint Logo
Javatpoint Logo

SJF CPU Scheduling Program in C++

What is the quickest scheduling of jobs?

The job or process scheduling method that adheres to the non-preemptive scheduling discipline is called shortest job first scheduling. In this case, the scheduler chooses the job or process from the waiting list with the shortest completion time and assigns the CPU to it. Because SJF is more optimal than FIFO and decreases average wait times, which will enhance throughput, it is preferred over FIFO.

Both preemptive and non-preemptive SJF algorithms are possible. Shortest-remaining-time-first scheduling is another name for preemptive scheduling. The new process emerges in the preemptive method while the existing process is still running. The scheduler will prevent the execution of the process with the shorter burst time if the burst of the newly incoming process is smaller than the burst time of the current process.

What is Turn Around, Wait, and Completion time?

  • Completion Time is the amount of time needed for the process to finish running.
  • Turnaround Time is the period of time between starting a procedure and finishing it.
  • Turnaround time is equal to the time it takes to complete a procedure and submit it.
  • The delay between turnaround time and burst time is called waiting time.
  • Turnaround time minus burst time equals waiting time.


Program for SJF Scheduling in C++


Processes  Burst Time	Waiting Time  Turn Around Time
   1	        5	        3	            8
   2	        3	        0	            3
   3	        6	        12	            18
   4	        5	        6	            11

Average waiting time = 5.25
Average turn around time = 10
Process executed in 1.33 seconds
Press any key to continue.
  • Whenever there is a tie, FCFS Scheduling decides who wins.
  • It is possible to employ SJF Scheduling in both preemptive and non-preemptive modes
  • 3-The Shortest Remaining Time First is the preemptive mode of Shortest Job First (SRTF).

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA