10 - FCFS and SJF Algorithm
10 - FCFS and SJF Algorithm
10 - FCFS and SJF Algorithm
EDUCATION
GOVERNMENT POLYTECHNIC, JALGAON
(0018)
A MICRO PROJECT
On
Implementation of FCFS and SJF scheduling algorithm
Project Guide
Mr. A. P. CHAUDHARI (Lecturer in IT)
1
CERTIFICATE
Seal of
Institution
2
GOVERNMENT POLYTECHNIC JALGAON
-SUBMISSION-
3
AKNWLDGMENT
This micro project would not have been possible without considerable
guidance and support. So, we would like to thank to those who have enable us to
complete this project.
Firstly, we would like to thank our project guide Mr. A.P.CHAUDHARI
(Lecturer in IT Dept , Government Polytechnic Jalgaon) and Head of IT
Department Mr. H. K. Nemade for providing the guideline with continuous
advice and feedback throughout the duration of finishing this project. We also
thank to the Dr. P.M. Patil (principal of Government Polytechnic Jalgaon) for
providing us the opportunity to embark on this project.
Secondly, we would also like to thank all other staff members of IT
Department that we may call upon for assistance since the genesis of this project
their opinion and suggestions have helped us in a realizing these projects.
4
INDEX
2. Algorithm 8
5. Conclusion 27
6. References 28
5
INTRODUCTION
Characteristics of FSCS:-
6
• To successfully implement it, the burst time/duration time of the
processes should be known to the processor in advance, which is
practically not feasible all the time.
• This scheduling algorithm is optimal if all the jobs/processes are
available at the same time. (either Arrival time is 0 for all, or Arrival
time is same for all)
7
ALGORITHM
Implementation : -
8
Shortest Job First ( Non - Preemptive ): -
Implementation : -
9
Shortest Job First ( Preemptive ): -
Implementation : -
// Driver code
int main()
{
//process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];
findavgTime(processes, n, burst_time);
return 0;
}
13
Shortest Job First ( Non - Preemptive ): -
#include <iostream>
int mat[10][6];
*a = *b;
*b = temp;
}
}
14
}
}
}
low = mat[j][2];
val = j;
15
mat[val][3] = temp + mat[val][2];
swap(mat[val][k], mat[i][k]);
}
}
int main()
{
16
cout << "Enter Arrival Time: ";
arrangeArrival(num, mat);
completionTime(num, mat);
"Time\tTurnaround Time\n";
}
}
18
Shortest Job First ( Preemptive ): -
#include <iostream>
struct Process {
int wt[])
{
int rt[n];
rt[i] = proc[i].bt;
19
int shortest = 0, finish_time;
// completed
while (complete != n) {
// current time`
minm = rt[j];
shortest = j;
check = true;
20
if (check == false) {
t++;
continue;
rt[shortest]--;
// Update minimum
minm = rt[shortest];
if (minm == 0)
minm = INT_MAX;
// executed
if (rt[shortest] == 0) {
// Increment complete
complete++;
check = false;
21
// Find finish time of current
// process
finish_time = t + 1;
wt[shortest] = finish_time -
proc[shortest].bt -
proc[shortest].art;
if (wt[shortest] < 0)
wt[shortest] = 0;
// Increment time
t++;
}
}
total_tat = 0;
// processes
findWaitingTime(proc, n, wt);
// all processes
// details
// Driver code
24
int main()
{
Process proc[] = { { 1, 6, 1 }, { 2, 8, 1 },
{ 3, 7, 2 }, { 4, 3, 3 } };
findavgTime(proc, n);
return 0;
}
25
ADVANTAGE AND DISADVANTAGE
Advantages : -
1. It is simple and easy to understand.
Disadvantages : -
1. The process with less execution time suffer i.e. waiting time
is often quite long.
2. Favors CPU Bound process then I / O bound process.
Advantages -
1. Shortest jobs are favored.
2. It is provably optimal, in that it gives the minimum average waiting time for a
given set of processes.
Disadvantages -
1. SJF may cause starvation, if shorter processes keep coming. This problem is
solved by aging.
2. It cannot be implemented at the level of short term CPU scheduling.
26
CONCLUSION
27
REFERENCES
• https://www.geeksforgeeks.org/program-for-fcfs-cpu-scheduling-set-1/
• https://www.geeksforgeeks.org/program-for-shortest-job-first-or-sjf-cpu-
scheduling-set-1-non-preemptive/?ref=lbp
• https://www.geeksforgeeks.org/program-for-shortest-job-first-sjf-scheduling-
set-2-preemptive/?ref=lbp
• https://www.wikipedia.org/
• https://www.google.co.in/
• https://www.geeksforgeeks.org/advantages-and-disadvantages-of-various-cpu-
scheduling-algorithms/
28