0% found this document useful (0 votes)
63 views

2) Shortest Job First Scheduling

CPU scheduling determines which process will run next and is handled by the operating system kernel. The goal is to allocate CPU time efficiently between processes while maintaining fairness. Common algorithms include first-in, first-out (FIFO); shortest job first (SJF); and round robin (RR).

Uploaded by

Abhijit Bala
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

2) Shortest Job First Scheduling

CPU scheduling determines which process will run next and is handled by the operating system kernel. The goal is to allocate CPU time efficiently between processes while maintaining fairness. Common algorithms include first-in, first-out (FIFO); shortest job first (SJF); and round robin (RR).

Uploaded by

Abhijit Bala
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

The average waiting time is now (6+0+3)/3=3 milliseconds. This reduction is substantial.

Thus,
the average waiting time under FIFO policy is generally not minimal and may vary substantially if the
processes CPU burst times vary greatly.

2] Shortest Job First Scheduling:-

This algorithm associates with each process the length of the process’s next CPU first. When the
CPU is available, it is assigned to process that has the smallest next CPU burst. If the next CPU bursts of
two processes are the same, FIFO scheduling is used to break the tie. The more appropriate term for this
scheduling method would be the shortest-next-CPU-burst algorithm, because scheduling depends on
the length of next CPU burst/process of a process, rather than the total length. We use the term SJF
because most people and textbooks use this term to refer to this type of scheduling.

As an example of SJF scheduling, consider the following set of processes, with the length of the
burst given in milliseconds.

Process Burst Time


P1 6
P2 8
P3 7
P4 3

Using SJF scheduling, we would schedule these processes according to the following Gantt chart:

P4 P1 P3 P2
0 3 9 16 30

The waiting time is 3ms for process P1, 16ms for process P2, 9ms for process P3 and 0ms for process P4.
Thus, the average waiting time is (3+16+9+0)/4=7ms. By comparison, if we were using the FIFO
scheduling scheme, the average rating time would be 10.25ms.

3] Round Robin Scheduling:-

The round robin scheduling algorithm designed especially for time scheduling systems. It is
similar to FIFO scheduling, but preemption is added to enable the system to switch between the
processed n. A small unit of time, called time quantum or time slice, is defined. A time slice is generally
for 10 to 100ms in length. The ready queue is treated as circular queue. This CPU scheduler goes around
the ready queue, allocating the CPU to each process for time interval of up to 1 time quantum.

To implement RR scheduling we keep the ready queue as a FIFO queue of process new process
are added to the tail of the ready queue. The CPU scheduler picks the first process from ready queue,
steps the timer interrupt after 1 time quantum, and dispatches the process. One of the two things will
then happen. The process may have a CPU burst less than one time quantum. In this case, the process
itself will be released the CPU voluntarily.
The scheduler will then proceed to the next process in the ready queue. Otherwise, if the CPU
burst of the currently running process in the longer than 1 time quantum, the timer will go off and will
cause an interrupt to the operating system, context switch will be executed and the process will be put
at the tail of the ready queue. The CPU scheduler wills the select the next process in the ready queue.

The average waiting time under the RR policy is often long. Consider the following set of process
that arrives at time 0, with the length of the CPU burst given in milliseconds:

Process Burst Time


P1 24
P2 3
P3 3

If we use a time quantum of 4ms, then the process P1 gets the first 4ms. Since it requires another 20ms,
it is preempted after the first time quantum, and the CPU is given to the next process in the queue,
process P. Process P2 does not need 4ms, so it quits before its time quantum expires. The CPU is then
given to the next process, process P3. Once each process has received 1 time quantum, the CPU is
returned to process P1 for an additional time quantum. The resulting RR schedule is as follows:

P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

Let us calculate the average waiting time for the above schedule. P1 waits for 6 milliseconds (10-
4), P2 waits for 4 milliseconds, &P3 waits for 7 milliseconds. Thus, the average waiting time is 17/3=5.66
milliseconds.

In the RR scheduling algorithm, no process is allocated the CPU for more than 1 time quantum in
a row (unless it is the only run able process).

Goals of Scheduling:-

1) Fairness:-
A scheduler makes sure each process gets its fair share of CPU and no process can suffer
indefinite post 1.
2) Policy enforcement:-
The scheduler has to make sure that system policy is enforced whenever they won’t be
able to run.
3) Efficiency:-
Scheduler should keep system busy all time when possible. If the CPU and all I/O devices
are kept running, then more work is done per second, if some components are idle.
4) Response time:-
A scheduler should minimize the turnaround time batch user must wait for an o/p.
CONCLUSION:

Hence, we have studied various scheduling algorithms.

QUESTION:

1) Compare FIFO, shortest job first and round robin algorithm.


2) What is CPU scheduling and process scheduling?

You might also like