Memory
Management
Algorithms: FCFS
and SJF
Memory management is a crucial aspect of operating systems. It's
responsible for allocating and managing the computer's main memory
(RAM) among different processes efficiently. This presentation will focus
on two fundamental memory management algorithms: First-Come First-
Served (FCFS) and Shortest Job First (SJF). We'll explore their
characteristics, compare their performance, and identify their strengths
and weaknesses.
by Roshan kumar
Introduction to Memory Management
Process Management Resource Allocation Efficiency and Security
Memory management is the Memory management is responsible Efficient memory management
foundation of process management. for allocating and de-allocating optimizes RAM utilization and
The OS allocates memory to different memory resources among various prevents memory leaks and
processes so they can execute processes. It determines how much fragmentation. It also ensures
independently and share resources memory each process needs and security by protecting processes from
efficiently. It ensures that each ensures that memory is not wasted. accessing each other's memory
process has access to the necessary spaces.
memory to function.
FCFS (First Come First
Served) Algorithm
1 Process Arrival
Processes arrive at the ready queue in a specific order. The FCFS
algorithm serves them based on their arrival time.
2 Process Execution
The process at the front of the queue gets allocated memory and
starts executing. It continues executing until it completes or is
interrupted.
3 Next Process
Once the first process completes, the next process in the queue is
served, and the cycle continues until all processes are served.
Characteristics of FCFS Algorithm
Simplicity Fairness Starvation
The FCFS algorithm is FCFS ensures fairness as all FCFS can lead to starvation if a long
straightforward and easy to processes are served in the order process arrives first, blocking
implement. It's a natural approach they arrived, regardless of their shorter processes that might have
for allocating memory, as processes execution time. This prevents arrived later. Short processes might
are served in the order they arrive. favoritism toward specific processes. have to wait indefinitely.
SJF (Shortest Job First)
Algorithm
1 Process Arrival 2 Shortest Job First
Processes arrive at the
ready queue, and their SJF selects the process with
estimated burst times (the the shortest burst time
time they need to execute) from the ready queue and
are known. allocates memory to it.
3 Process Completion
Once the selected process finishes executing, the algorithm
repeats the selection process by choosing the next shortest job
in the queue.
Characteristics of SJF Algorithm
Characteristic Description
Efficiency SJF minimizes the average waiting
time for all processes, improving
overall system efficiency.
Priority Based It gives priority to shorter jobs,
ensuring they are executed quickly
and reduce the overall waiting time.
Preemption SJF can be preemptive, where a
shorter process arriving later can
interrupt a longer process, leading to
improved efficiency.
Difficulty Accurate prediction of burst times
can be challenging, and SJF's
preemptive version requires overhead
for context switching.
Comparison of FCFS and
SJF Algorithms
FCFS
Simple, easy to implement, fair to all processes, but can
lead to starvation and long waiting times for short
processes.
SJF
More efficient in terms of minimizing waiting times,
prioritizes short processes, but requires accurate burst
time estimation and can be complex to implement.
Conclusion and Key Takeaways
Simplicity vs. Efficiency
FCFS prioritizes simplicity and fairness, while SJF focuses on efficiency by minimizing
waiting times. The choice depends on the specific needs of the system.
Process Prioritization
SJF gives priority to short jobs, potentially leading to better overall performance but
requiring accurate burst time estimates.
Real-World Applications
FCFS is suitable for systems where simplicity and fairness are crucial, while SJF is often
used in systems where efficiency and quick execution are paramount.