program of SJF(Shortest job first ) Scheduling algorithm (Non -preemptive) of Os in c
Here we are going discuss all things about the SJF scheduling algorithm i.e what is SJF , what are the advantage of SJF , what is disadvantage of SJF ,Code of SJF.
What is SJF(Shortest job First) scheduling:-
As it is clear by the name of this scheduling algorithm the job which have the less burst time will get the CPU first .it is the best method to minimize the waiting time .it is of two type
2. non preemptive
Characteristics:-
- Sjf scheduling can be either preemptive or non-preemptive.
- IN SJF CPU is assigned to the process that has the smallest next CPU Burst time.
- If the next CPU Burst of two process is the same then FCFS scheduling is used to break the tie.
- This process give the minimum average waiting time for a given processes.
Code:-
In this code first we are creating the structure for the process in which we are declaring the id , waiting time , Arrival time , Burst time and turn around time .then after an array of the structure type.
logic:-
1. After taking the input first we sort the input on the basis of Arrival time (i.e the process which have less Arrival time will come first).
Here one more things we will do . we will check that the arrival time of all the processes are different or not. (Example:- if all the processes comes at the same time then we don’t need to sort the array on the basis of arrival time ) . for checking this we will use check_ar.
2. After doing this if processes are arrived at the different time then we can easily calculate the waiting and turn around time for the first process. and for other process first we will find the minimum burst time of the process which are arrived at cmp_time (completion time of the previous process) .
You can easily understand by Following code .
Output:-
Recommended post:-
- Program to find cycle in the graph
- Implementation of singly link list
- Implementation of queue by using link list
- Algorithm of quick sort
- stack by using link list
- program to find preorder post order and inorder of the binary search tree
- How to set limit in the floating value in python
- What is boolean data type
- How to print any character without using format specifier
- Very Cool numbers | Hacker earth solution
- Birthday party | Hacker earth solution
- Most frequent | hacker earth problem solution
- program to find symetric difference of two sets
- cost of balloons | Hacker earth problem solution
- Chacha o chacha | hacker earth problem solution
- jadu and dna | hacker earth solution
- Bricks game | hacker earth problem
- Anti-Palindrome strings | hacker earth solution
- connected components in the graph | hacker earth data structure
- odd one out || hacker earth problem solution