0% found this document useful (0 votes)
43 views6 pages

Non-Preemptive CPU Scheduling Algorithms

what is Non primitive scheduling algorithm?

Uploaded by

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

Non-Preemptive CPU Scheduling Algorithms

what is Non primitive scheduling algorithm?

Uploaded by

Abu Sufian
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Non primitive scheduling algorithm

Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm


using Segment Tree
Shortest job first (SJF) or shortest job next, is a scheduling policy that
selects the waiting process with the smallest execution time to execute next.
SJN is a non-preemptive algorithm.

 Shortest Job first has the advantage of having a minimum average waiting
time among all scheduling algorithms.
 It is a Greedy Algorithm.
 It may cause starvation if shorter processes keep coming. This problem
can be solved using the concept of ageing.
 It is practically infeasible as Operating System may not know burst time
and therefore may not sort them. While it is not possible to predict
execution time, several methods can be used to estimate the execution
time for a job, such as a weighted average of previous execution times.
SJF can be used in specialized environments where accurate estimates
of running time are available.
For example:
In the above example, since the arrival time of all the processes is 0, the
execution order of the process is the ascending order of the burst time of the
processes. The burst time is given by the column duration. Therefore, the
execution order of the processes is given by:

P4 -> P1 -> P3 -> P2

Longest Job First (LJF) CPU Scheduling Algorithm


Longest Job First (LJF) is a non-preemptive scheduling algorithm. This
algorithm is based on the burst time of the processes. The processes
are put into the ready queue based on their burst times i.e., in
descending order of the burst times. As the name suggests this
algorithm is based on the fact that the process with the largest burst
time is processed first. The burst time of only those processes is
considered that have arrived in the system until that time. Its
preemptive version is called Longest Remaining Time First (LRTF)
algorithm.
Prerequisite: Process Management | CPU Scheduling
Characteristics of Longest Job First(Non-Preemptive)
 Among all the processes waiting in a waiting queue, the CPU is
always assigned to the process having the largest burst time.
 If two processes have the same burst time then the tie is broken
using FCFS i.e. the process that arrived first is processed first.
 LJF CPU Scheduling can be of both preemptive and non-preemptive
types.
Advantages of Longest Job First(LJF)
 No other process can execute until the longest job or process
executes completely.
 All the jobs or processes finish at the same time approximately.
Disadvantages of Longest Job First CPU Scheduling Algorithm
 This algorithm gives a very high average waiting time and average
turn-around time for a given set of processes.
 This may lead to a convoy effect.
 It may happen that a short process may never get executed and the
system keeps on executing the longer processes.
 It reduces the processing speed and thus reduces the efficiency and
utilization of the system
 Example-1: Consider the following table of arrival time and burst time
for four processes P1, P2, P3 and P4.
Processes Arrival time Burst Time

P1 1 ms 2 ms

P2 2 ms 4 ms

P3 3 ms 6 ms

P4 4 ms 8 ms
Gantt chart will be as following below:

Therefore, final table look like,

Output :
Total Turn Around Time = 40 ms
So, Average Turn Around Time = 40/4 = 10.00 ms
And, Total Waiting Time = 20 ms
So, Average Waiting Time = 20/4 = 5.00 ms

Priority CPU Scheduling


Priority scheduling is a non-preemptive algorithm and one of the most
common scheduling algorithms in batch systems. Each process is
assigned first arrival time (less arrival time process first) if two
processes have same arrival time, then compare to priorities (highest
process first). Also, if two processes have same priority then compare
to process number (less process number first). This process is
repeated while all process get executed.

Implementation –
1. First input the processes with their arrival time, burst time and
priority.
2. First process will schedule, which have the lowest arrival time, if
two or more processes will have lowest arrival time, then whoever
has higher priority will schedule first.
3. Now further processes will be schedule according to the arrival time
and priority of the process. (Here we are assuming that lower the
priority number having higher priority). If two process priority are
same then sort according to process number.
Note: In the question, They will clearly mention, which number will
have higher priority and which number will have lower priority.
4. Once all the processes have been arrived, we can schedule them
based on their priority.

Gantt Chart –
Examples –
Input :
process no-> 1 2 3 4 5
arrival time-> 0 1 3 2 4
burst time-> 3 6 1 2 4
priority-> 3 4 9 7 8
Output :
Process_no arrival_time Burst_time Complete_time Turn_Around_Time
Waiting_Time
1 0 3 3 3 0
2 1 6 9 8 2
3 3 1 16 13 12
4 2 2 11 9 7
5 4 4 15 11 7
Average Waiting Time is : 5.6
Average Turn Around time is : 8.8

Common questions

Powered by AI

In the Shortest Job First (SJF) algorithm, starvation occurs when shorter jobs continue to arrive, causing longer jobs to wait indefinitely . Similarly, in the Longest Job First (LJF) algorithm, shorter processes can experience starvation because the CPU continuously prioritizes longer jobs for execution . This issue can be mitigated by implementing priority aging, where the priority of waiting processes increases over time, reducing their wait time and ensuring they eventually receive CPU time . This threshold-based strategy balances the load and reduces the starvation risk in both scheduling approaches. Additionally, properly estimating burst times and dynamically adjusting them based on current system state and historical data can aid in further mitigating starvation issues .

The Longest Job First (LJF) scheduling algorithm has several drawbacks when compared to other non-preemptive algorithms. It tends to produce a high average waiting time due to the prioritization of longer processes . This can lead to increased turnaround times and potential inefficiencies because shorter processes may experience significant delays. Additionally, LJF can create a convoy effect, where short processes waiting behind a lengthy job lead to decreased overall system throughput and underutilization of resources . Furthermore, there is a risk of starvation for shorter processes, further exacerbating these inefficiencies .

The Shortest Job First (SJF) scheduling algorithm has the advantage of minimizing average waiting time compared to other scheduling algorithms due to its greedy approach of executing the shortest process first . However, it can lead to starvation as shorter processes may continuously arrive, delaying longer processes indefinitely. On the other hand, the Longest Job First (LJF) algorithm, while also non-preemptive, tends to produce a high average waiting time because longer processes are prioritized , leading to potential inefficiencies and increased turnaround times. The LJF algorithm can also struggle with process starvation, where shorter jobs may never execute if longer jobs continue to arrive .

Shortest Job First (SJF) is considered a 'Greedy Algorithm' because it chooses to execute the process with the smallest execution time that is available at every step, aiming to minimize the average waiting time locally without regard for future processes . The implication of this greedy characterization is that SJF can achieve optimal efficiency in terms of average waiting time when accurate burst times are known . However, this approach may not always yield globally optimal results in dynamic environments because it does not account for the potential of longer, subsequent processes creating bottlenecks if their delays might optimize later executions .

The convoy effect occurs in CPU scheduling algorithms when a process with a long burst time holds up shorter processes, causing them to wait unnecessarily until it finishes execution . This often occurs in the Longest Job First (LJF) scheduling algorithm when longer tasks are prioritized, resulting in a line-up of shorter jobs behind them. The consequence of the convoy effect is notably decreased system throughput and efficiency, as the system is effectively bottlenecked by the lengthy process execution, leading to higher overall turnaround times and inefficient CPU utilization .

To estimate the burst time in the Shortest Job First (SJF) scheduling algorithm, methods such as using a weighted average of previous execution times are employed . However, a significant challenge with these methods is their reliance on accurate historical data, which may not always be available or reflective of future execution characteristics, leading to potential misestimations and ineffective scheduling decisions due to these inaccuracies .

The concept of priority in CPU scheduling algorithms significantly influences their efficacy by determining which processes are executed first in non-preemptive systems. In priority scheduling, processes are given a priority level, and those with higher priority (usually represented by lower numerical values) are chosen for execution first, leading to reduced waiting times for critical processes . However, this method may lead to starvation of lower-priority processes if high-priority tasks continue to enter the system, necessitating considerations for priority adjustment, such as priority aging, to ensure fairness and improve the overall responsiveness of the system .

The Gantt chart plays a crucial role in visualizing and understanding the performance of various scheduling algorithms by displaying the order and duration of processes in a timeline format . It offers a clear representation of the scheduling order and waiting times, allowing for direct observation and comparison of how different algorithms affect process execution. By illustrating the sequence of operations, Gantt charts can help identify inefficiencies such as long waiting times, the convoy effect, or potential starvations under different scheduling rules . It is particularly valuable for evaluating CPU scheduling efficiency as it allows for the precise calculation of metrics like average waiting time, turnaround time, and system throughput, informing decisions on the optimal scheduling strategy for a given workload.

Priority Scheduling, a non-preemptive algorithm, offers the advantage of ensuring that high-priority processes are completed promptly, which can be critical in systems where certain tasks must be prioritized . However, in terms of system performance, this can lead to unfairness as lower-priority processes may suffer from starvation, waiting indefinitely if higher-priority processes keep arriving . This impacts overall system fairness and can reduce efficiency by causing lower-priority processes to experience delays. Despite these disadvantages, it can be adapted for improved fairness through techniques like priority aging, which increase the priority of processes that have been waiting longer, helping mitigate the starvation problem and improving overall system service quality .

Implementing the Shortest Job First (SJF) scheduling algorithm in dynamic environments where process burst times are not pre-known is practically challenging. SJF relies on the assumption that the burst times are known, and it functions optimally when these times are estimated accurately . In environments where burst times fluctuate or aren't predictable, estimating these times can be problematic, leading to potential inefficiencies and suboptimal scheduling decisions. However, in specialized contexts where historical data can accurately project burst times, such as batch processing or stable environments, SJF may still be applied effectively with appropriate forecasting methods . Nonetheless, without such data, practical implementation of SJF may yield irregular outcomes, underscoring the need for adaptable and predictive scheduling algorithms in dynamic contexts. Alternative algorithms that do not rely on precise burst time estimations would be more suitable under such circumstances.

You might also like