Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
195 views10 pages

OSY Micro Project

The document discusses the Shortest Job First (SJF) non-preemptive scheduling algorithm. It describes how SJF works by always selecting the waiting process with the shortest execution time to execute next without preemption. The document also notes that SJF minimizes average waiting time but can lead to starvation of longer processes.

Uploaded by

ethicalninja7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views10 pages

OSY Micro Project

The document discusses the Shortest Job First (SJF) non-preemptive scheduling algorithm. It describes how SJF works by always selecting the waiting process with the shortest execution time to execute next without preemption. The document also notes that SJF minimizes average waiting time but can lead to starvation of longer processes.

Uploaded by

ethicalninja7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Maharashtra State Board of Technical Education, Mumbai

OPERATING SYSTEM
MICRO PROJECT
Topic – Shortest Job First (Non-Preemptive)
Prathamesh Bhushan Gawas – 2101170166
Varad Makarand Paradkar - 2101170168

Submitted At
Department of Computer Engineering
Government Polytechnic, Malvan
A/P-Kumbharmath, Tal-Malvan, Dist-Sindhudurg
416606
(Academic Year: -2023-2024)
INTRODUCTION
Shortest Job First (SJF) non-preemptive is a
scheduling algorithm that selects the waiting process
with the smallest execution time to execute next. Once a
process is allocated the CPU, it is not interrupted until it
completes its execution. This is in contrast to preemptive
SJF, where a shorter process can interrupt a longer
process that is already executing.
SJF non-preemptive is a simple and efficient
algorithm that can be implemented easily. It has the
advantage of minimizing average waiting time among all
scheduling algorithms. This is because shorter processes
are given priority, which reduces the amount of time that
longer processes have to wait.
However, SJF non-preemptive can also lead to
starvation. This occurs when a long process arrives and
there are a number of shorter processes waiting to be
executed. The long process will not be able to run until
all of the shorter processes have been completed, which
can take a long time. Despite this drawback, SJF non-
preemptive is a widely used scheduling algorithm. It is
particularly well-suited for batch processing systems,
where the goal is to minimize the overall time, it takes to
complete a set of jobs.
In summary, SJF non-preemptive is a simple and
efficient scheduling algorithm that minimizes average
waiting time. However, it can also lead to starvation.
CHARATERISTC OF FCFS
ALGORITHM
 Minimum average waiting time: SJF non-preemptive has
the minimum average waiting time among all scheduling
algorithms. This is because shorter processes are given
priority, which reduces the amount of time that longer
processes have to wait.

 Greedy algorithm: SJF non-preemptive is a greedy


algorithm. This means that it makes the best local decision
at each time step without considering the long-term
consequences.

 Starvation: SJF non-preemptive can lead to starvation.


This occurs when a long process arrives and there are a
number of shorter processes waiting to be executed. The
long process will not be able to run until all of the shorter
processes have been completed, which can take a long time.

 Non-preemptive: Once a process is allocated the CPU, it is


not interrupted until it completes its execution. This can
lead to longer processes blocking shorter processes.

 Simple and efficient: SJF non-preemptive is a simple and


efficient algorithm that can be implemented easily.
SOURCE CODE
#include <stdio.h>
int main()
{
// Matrix for storing Process Id, Burst
// Time, Average Waiting Time & Average
// Turn Around Time.
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
printf("Enter number of process: ");
scanf("%d", &n);
printf("Enter Burst Time:\n");
// User Input Burst Time and alloting Process Id.
for (i = 0; i < n; i++) {
printf("P%d: ", i + 1);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
}
// Sorting process according to their Burst Time.
for (i = 0; i < n; i++) {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1])
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;

temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
// Calculation of Waiting Times
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++)
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
printf("P BT WT TAT\n");
// Calculation of Turn Around Time and printing the
// data.
for (i = 0; i < n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
printf("P%d %d %d %d\n", A[i][0],
A[i][1], A[i][2], A[i][3]);
}
avg_tat = (float)total / n;
printf("Average Waiting Time= %f", avg_wt);
printf("\nAverage Turnaround Time= %f", avg_tat);
}
OUTPUT
 Program start:

 Entering Numbers of Process:


 Entering Brust time & Arrival time:

 Calculating Turnaround time & Waiting time & Average


of Turnaround time & Average of Wating time:

EXAMPLE
 Batch processing systems: SJF is well-suited for
batch processing systems where the execution time of
jobs is known in advance. For example, SJF can be
used to schedule jobs such as data analysis, image
processing, and scientific computing.

 Production systems: SJF can be used in production


systems where jobs are typically short and have
predictable execution times. For example, SJF can be
used to schedule jobs such as printing, packaging, and
quality control.

 Real-time systems: SJF can be used in real-time


systems where deadlines must be met. For example,
SJF can be used to schedule tasks in a control system
or a medical device.

ADVANTAGES/
DISADVANTAGES
 Advantages:
 Reduces average waiting time: SJF ensures that
shorter jobs are executed first, which reduces the
overall waiting time for all jobs.
 Ideal for batch processing: SJF is well-suited for batch
processing systems where the execution time of jobs is
known in advance.
 Simple to implement: SJF is a simple and easy-to-
understand scheduling algorithm.
 Low overhead: SJF has low scheduling overhead as it
does not involve frequent context switching.

 Disadvantages:
 Reduces average waiting time: SJF ensures that shorter jobs
are executed first, which reduces the overall waiting time for
all jobs.
 Ideal for batch processing: SJF is well-suited for batch
processing systems where the execution time of jobs is known
in advance.
 Simple to implement: SJF is a simple and easy-to-understand
scheduling algorithm.
 Low overhead: SJF has low scheduling overhead as it does
not involve frequent context switching.

CONCLUSION
Overall, SJF non-preemptive scheduling is a
good choice for batch processing systems where the
execution time of jobs is known in advance. However, it is
not suitable for interactive systems where short jobs need to
be executed quickly.

You might also like