OS Notes
OS Notes
Unit 1
Introduction
Simple Batch Systems:
Multiprogrammed Batch Systems:
Time Sharing Systems:
Personal-Computer Systems:
Parallel Systems:
Distributed Systems:
Real-Time Systems:
Operating Systems as Resource Managers:
Processes
Introduction to Processes:
Process States:
Process Management:
Interrupts
Interprocess Communication (IPC):
Threads: Introduction and Thread States
Thread Operation:
Threading Models:
Processor Scheduling:
Scheduling Levels:
Preemptive Scheduling:
Non-Preemptive Scheduling:
Priorities in Scheduling:
Scheduling Objectives:
Scheduling Criteria:
Scheduling algorithms
Demand Scheduling:
Real-Time Scheduling:
Unit 2
Process Synchronization: Mutual Exclusion
Software Solutions to the Mutual Exclusion Problem:
Hardware Solutions to the Mutual Exclusion Problem:
Semaphores
Critical Section Problems
Operating System 1
Case Study: The Dining Philosophers Problem
Case Study: The Barber Shop Problem
Memory Organization
Memory Hierarchy
Memory Management Strategies
Contiguous Memory Allocation vs. Non-Contiguous Memory Allocation
Partition Management Techniques
Logical Address Space vs. Physical Address Space
Swapping
Paging
Segmentation
Segmentation with Paging Virtual Memory: Demand Paging
Page Replacement and Page-Replacement Algorithms
Performance of Demand Paging
Thrashing
Demand Segmentation and Overlay Concepts
Unit 1
Introduction
An Operating System (OS) is a fundamental component of a computer system that acts
as an intermediary between the hardware and the user or application software. It serves
several crucial functions:
Operating System 2
4. File System Management: The OS handles file and directory management,
allowing users to store, retrieve, and organize data efficiently. It manages file
permissions and access control.
6. User Interface: The OS provides a user-friendly interface for users to interact with
the system. This interface can be command-line (text-based) or graphical (GUI),
depending on the OS.
8. Error Handling: The OS provides mechanisms for handling errors and exceptions,
preventing system crashes due to software bugs.
10. Task Scheduling: The OS employs scheduling algorithms to determine the order in
which processes are executed, ensuring fair allocation of CPU time and system
responsiveness.
1. Windows: Microsoft Windows is a widely used OS known for its graphical user
interface and compatibility with a variety of software applications.
2. Linux: Linux is an open-source operating system known for its stability, security,
and flexibility. It comes in various distributions, such as Ubuntu, CentOS, and
Debian.
4. Unix: Unix is an older, robust OS that has influenced many other operating
systems, including Linux.
Operating System 3
5. Android: Android is a popular mobile operating system used in smartphones and
tablets.
6. iOS: iOS is Apple's mobile operating system used in iPhones and iPads.
Batch Jobs: In a simple batch system, users submit their jobs to the system as
batch jobs. A batch job typically consists of one or more programs or tasks that need
to be executed sequentially.
Job Scheduling: The OS's primary responsibility is to schedule and manage the
execution of batch jobs. It maintains a job queue and selects the next job to run
based on criteria like job priority.
Job Control Language (JCL): Users provide job control language statements in
their batch job submissions. JCL specifies details like the input and output files,
resource requirements, and other job-specific information.
Job Spooling: Jobs are often spooled (spooling stands for Simultaneous Peripheral
Operations On-line) before execution. This means they are placed in a queue and
stored on secondary storage, making it easier for the system to retrieve and execute
them.
No Interactivity: Unlike interactive systems where users can provide input during
program execution, simple batch systems have no user interaction during job
execution. They are suited for long-running and computationally intensive tasks.
Operating System 4
Advantages of Simple Batch Systems:
Efficiency: Simple batch systems are efficient for processing large volumes of
similar tasks without the overhead of user interaction.
Error Recovery: Batch systems can be designed to restart a job in case of system
failures, improving error recovery.
Lack of Interactivity: They are not suitable for tasks that require user interaction,
making them unsuitable for real-time or interactive applications.
Limited Flexibility: Users need to submit jobs in advance, which may lead to
delays if a high-priority task suddenly arises.
Job Pool: In a multiprogrammed batch system, there is a job pool that contains a
collection of batch jobs. These jobs are ready to run and are loaded into memory as
space becomes available.
Job Scheduling: The operating system employs job scheduling algorithms to select
the next job from the job pool and load it into memory. This helps in reducing idle
time of the CPU and improves system throughput.
Operating System 5
Memory Management: Multiprogrammed batch systems manage memory
efficiently by allocating and de-allocating memory space for each job. Jobs may
need to be swapped in and out of memory to make the best use of available
resources.
I/O Overlap: These systems aim to overlap I/O operations with CPU processing.
While one job is waiting for I/O, another job can utilize the CPU, enhancing overall
system performance.
Resource Utilization: Resources are used efficiently as they are not wasted on idle
time. This leads to better CPU and I/O device utilization.
Increased Overhead: The need to load and swap jobs in and out of memory
introduces some overhead in the system.
Contention for Resources: With multiple jobs running concurrently, contention for
resources like memory and I/O devices can arise.
Operating System 6
Priority Inversion: Job prioritization can sometimes lead to priority inversion issues
where lower-priority jobs block resources needed by higher-priority ones.
Time Slicing: The CPU's time is divided into small time slices, and each user or
process is allocated a time slice to execute their tasks. This provides the illusion of
concurrent execution for multiple users.
Resource Sharing: Resources like CPU, memory, and I/O devices are shared
among users or processes. The system ensures fair access to resources.
Response Time: They are designed for fast response times to ensure that users
can interact with the system in real-time.
Personal-Computer Systems:
Personal Computer (PC) Systems are designed for individual users and small-scale
computing needs. Here are the key characteristics:
Single User: PC systems are typically single-user systems, designed for use by a
single individual.
Operating System 7
User-Friendly GUI: They often have a graphical user interface (GUI) that makes it
easy for users to interact with the system.
Limited Resource Sharing: PC systems are not designed for heavy multi-user
interaction or resource sharing. They focus on providing resources to a single user's
tasks.
Broad Application: PC systems are used for a wide range of applications, from
word processing and web browsing to gaming and multimedia.
Parallel Systems:
Parallel Systems are designed to execute tasks concurrently by using multiple
processors or cores. Here are the key aspects of parallel systems:
High Performance: Parallel systems offer high computing power and are used for
scientific computing, simulations, and tasks that can be divided into parallel threads.
Challenges: Developing parallel software can be complex due to issues like data
synchronization and load balancing.
Each of these types of systems serves different purposes and has its unique
characteristics, catering to specific user needs and computing requirements.
Distributed Systems:
Distributed Systems are a collection of interconnected computers that work together as
a single, unified system. Here are the key aspects of distributed systems:
Operating System 8
Multiple Machines: Distributed systems consist of multiple independent machines
or nodes that communicate and collaborate to perform tasks.
Resource Sharing: Resources like processing power, memory, and data can be
shared across the network, allowing for more efficient use of resources.
Fault Tolerance: They are designed to handle failures gracefully, ensuring that the
system continues to function even if some nodes fail.
Real-Time Systems:
Real-Time Systems are designed to respond to events or input within a predefined time
constraint. They are used in applications where timing and predictability are critical.
Here are the key characteristics of real-time systems:
Timing Constraints: Real-time systems have strict timing constraints, and tasks
must be completed within specific time limits.
Hard and Soft Real-Time: Real-time systems can be classified as hard real-time
(where missing a deadline is catastrophic) or soft real-time (where occasional
missed deadlines are acceptable).
Applications: Real-time systems are used in areas like aviation (flight control
systems), automotive (engine control units), and industrial automation (robotics).
Both distributed systems and real-time systems are specialized types of computer
systems, each with its unique requirements and applications. Distributed systems focus
on resource sharing and scalability across multiple machines, while real-time systems
prioritize time-bound responses and determinism.
Operating System 9
Operating Systems as Resource Managers:
Operating Systems (OS) act as resource managers that oversee and control the
allocation and utilization of a computer system's hardware and software resources.
Here's how an OS functions as a resource manager:
3. File System Management: It manages the file system, allowing users to create,
read, write, and delete files. The OS enforces file access permissions and maintains
the file hierarchy.
7. Error Handling: The OS provides mechanisms for handling errors and exceptions,
preventing system crashes due to software bugs or hardware failures. This includes
error reporting, logging, and graceful degradation.
Operating System 10
9. Security: OSs implement security measures like encryption, firewalls, and access
controls to protect the system from unauthorized access and data breaches.
10. Load Balancing: In distributed systems, the OS manages load balancing, ensuring
that tasks are distributed evenly across the network to prevent overloading of
certain nodes.
11. Virtualization: Many modern OSs offer virtualization capabilities, allowing multiple
virtual machines (VMs) to run on a single physical server. This is essential for cloud
computing and server consolidation.
Processes
Introduction to Processes:
In the context of operating systems, a process is a fundamental concept that represents
the execution of a program. It's a unit of work in a computer system that can be
managed and scheduled by the operating system. Here's an overview of processes:
A process consists of the program's code, its data, and the execution context,
including the program counter, registers, and the stack.
Each process operates in its own isolated memory space, which ensures that one
process cannot directly interfere with or access the memory of another process.
Process States:
Operating System 11
Processes go through different states during their lifecycle. These states represent the
different stages a process can be in. The typical process states are:
1. New: In this state, a process is being created but has not yet started execution.
2. Ready: A process in the ready state is prepared to run and is waiting for its turn to
be executed. It's typically waiting in a queue.
3. Running: A process in the running state is actively executing its code on the CPU.
4. Blocked (or Waiting): When a process is unable to continue its execution due to
the need for some external event (e.g., I/O operation, user input), it enters the
blocked state and is put on hold until the event occurs.
Operating System 12
Process Management:
Process management is a critical aspect of an operating system's responsibilities. It
involves various tasks related to process creation, scheduling, and termination. Here's
an overview of process management:
1. Process Creation: When a user or system request initiates a new process, the OS
is responsible for creating the process. This includes allocating memory, initializing
data structures, and setting up the execution environment.
6. Process Priority and Control: The OS allows users to set process priorities, which
influence their order of execution. It also provides mechanisms to control and
monitor processes.
Effective process management is essential for the efficient and stable operation of a
computer system, enabling multiple programs to run simultaneously, share resources,
and respond to user and system needs.
Interrupts
In the context of operating systems and computer architecture, an interrupt is a signal or
event that halts the normal execution of a program to transfer control to a specific
Operating System 13
routine, often called an interrupt service routine (ISR) or interrupt handler. Interrupts play
a crucial role in modern computing systems by allowing the operating system to respond
to events and requests in a timely and efficient manner. Here are the key aspects of
interrupts:
1. Types of Interrupts:
Software Interrupts: Also known as software traps or system calls, these are
generated by software programs to request specific services from the operating
system. For example, a program might request I/O operations or memory
allocation through software interrupts.
Exceptions: Exceptions are similar to interrupts but are typically generated due
to errors or exceptional conditions, such as division by zero, invalid memory
access, or illegal instructions. These events cause the CPU to transfer control to
an exception handler.
2. Interrupt Vector: Each type of interrupt is associated with a unique interrupt vector,
which is essentially an address pointing to the location of the corresponding
interrupt service routine (ISR) in memory. When an interrupt occurs, the CPU uses
this vector to find and execute the appropriate ISR.
4. Interrupt Handling: When an interrupt occurs, the CPU temporarily suspends the
currently executing program and transfers control to the ISR associated with the
interrupt. The ISR performs the required actions, which may include saving the
context of the interrupted program, processing the interrupt, and restoring the
program's context to resume execution.
5. Context Switching: Interrupts often involve context switching, where the CPU
switches from one program's context to another. This allows the operating system to
maintain the illusion of concurrent execution, even on single-core processors.
Operating System 14
6. Interrupt Latency: Interrupts are designed to be responsive, but they introduce
some delay (interrupt latency) in handling the event. Reducing interrupt latency is
essential in real-time and critical systems.
1. Shared Memory:
Shared memory is a fast and efficient method of IPC since it doesn't involve the
overhead of copying data between processes.
2. Message Passing:
Operating System 15
Message-passing can be either synchronous (blocking) or asynchronous (non-
blocking), depending on whether processes wait for a response or continue their
execution.
Pipes are a one-way communication channel that allows data to flow in one
direction between processes.
Named pipes (FIFOs) are similar but have a well-defined name in the file
system, allowing unrelated processes to communicate using a common pipe.
Pipes and FIFOs are often used in command-line environments to create data
pipelines.
4. Sockets:
They are widely used for client-server applications and network communication.
5. Signals:
Signals are often used for simple forms of IPC and for handling events like
process termination.
7. Message Queues:
Operating System 16
Message queues are a form of message-passing IPC where messages are
placed in a queue and processes can read or write from the queue in a
controlled and ordered manner.
IPC is fundamental for modern operating systems and plays a crucial role in enabling
processes to work together, share data, and synchronize their actions. The choice of
IPC method depends on factors such as the nature of the communication, performance
requirements, and security considerations.
1. Thread vs. Process: A process is a separate program execution with its own
memory space, file handles, and system resources. Threads, on the other hand,
share the same memory space as the process and have their own execution
context, such as program counter and registers.
2. Benefits of Threads:
Operating System 17
3. Types of Threads:
Thread States:
Threads go through different states during their lifecycle, just like processes. The typical
thread states are:
1. New: In this state, a thread is created but has not yet started execution.
2. Runnable: A thread in the runnable state is ready to execute and waiting for the
CPU. It is typically waiting in a queue and is eligible for execution.
3. Running: A thread in the running state is actively executing its code on the CPU.
4. Blocked (or Waiting): When a thread cannot continue its execution due to the need
for some external event (e.g., I/O operation), it enters the blocked state and is put
on hold until the event occurs.
Thread Transitions:
Threads transition between these states based on various factors, including their
priority, the availability of CPU time, and external events. Thread scheduling algorithms
determine which thread runs next and aim to provide fair execution and efficient
resource utilization.
Thread Management:
Operating systems provide APIs and libraries to create, manage, and synchronize
threads. Popular programming languages like C, C++, Java, and Python have built-in
support for threading. Threads can communicate and synchronize their activities using
synchronization primitives like semaphores, mutexes, and condition variables.
Operating System 18
Effective thread management is crucial for achieving concurrent execution in
applications, improving performance, and making efficient use of modern multicore
processors. However, it also introduces challenges related to synchronization, data
sharing, and avoiding race conditions.
Thread Operation:
Thread operations are fundamental for creating, managing, and controlling threads
within a program or process. Here are the key thread operations:
1. Thread Creation:
2. Thread Termination:
Threads can terminate for various reasons, such as completing their tasks,
receiving a termination signal, or encountering an error. Proper thread
termination is essential to release resources and avoid memory leaks.
Operating System 19
3. Thread Synchronization:
4. Thread Joining:
A thread can wait for another thread to complete its execution by using a thread
join operation. This is often used to wait for the results of a thread's work before
continuing with the main thread.
5. Thread Detachment:
Threads can be detached from the calling thread, which allows them to continue
running independently. Detached threads automatically release their resources
when they terminate, without requiring the main thread to join them.
6. Thread Prioritization:
Some threading models or libraries allow you to set thread priorities, which
influence the order in which threads are scheduled to run by the operating
system.
7. Thread Communication:
Threading Models:
Threading models define how threads are created, scheduled, and managed within a
program or an operating system. Different threading models offer various advantages
and trade-offs, depending on the application's requirements. Here are common
threading models:
1. Many-to-One Model:
2. One-to-One Model:
It offers fine-grained control but may have higher overhead due to the increased
number of kernel threads.
3. Many-to-Many Model:
This model seeks to balance control and efficiency by allowing both user-level
and kernel-level threads.
4. Hybrid Model:
The choice of a threading model depends on factors like the application's requirements,
the platform's support, and the trade-offs between control, resource usage, and
performance. It's essential to select the appropriate model to achieve the desired
concurrency and efficiency in a multithreaded application.
Processor Scheduling:
Processor scheduling is a core component of operating systems that manages the
execution of processes and threads on a CPU. It aims to allocate CPU time efficiently
and fairly to multiple competing processes. Below, we'll explore various aspects of
processor scheduling in detail.
Operating System 21
Scheduling Levels:
Scheduling levels, also known as scheduling domains, represent the different stages at
which scheduling decisions are made within an operating system. These levels help
determine which process or thread gets access to the CPU at any given time. There are
typically three primary scheduling levels:
Role: Long-term scheduling selects processes from the job pool, which is a queue
of new processes waiting to enter the system.
Characteristics:
It determines when and how many processes should be admitted to the system.
This decision is influenced by factors like available memory, CPU load, and
process mix.
2. Medium-Term Scheduling:
Role: This level of scheduling determines which processes that are already in
memory should be suspended (swapped out) to secondary storage or moved back
into memory (swapped in).
Characteristics:
Operating System 22
It plays a vital role in managing memory effectively, ensuring that the system
remains responsive and doesn't become sluggish due to excessive memory
consumption.
Role: Its primary goal is to optimize CPU utilization, response time, and overall
system throughput.
Characteristics:
The short-term scheduler needs to make quick decisions based on factors like
process priorities, burst times, and fairness.
Operating System 23
In summary, scheduling levels are crucial for managing processes in an operating
system. Long-term scheduling handles the admission of new processes, medium-term
scheduling manages memory resources, and short-term scheduling optimizes CPU
utilization and responsiveness. Each level of scheduling has its unique objectives and
time scales, contributing to the overall efficiency and performance of the system.
Preemptive Scheduling:
Preemptive scheduling is a scheduling policy where the operating system has the
authority to interrupt a running process and allocate the CPU to another process if a
higher-priority process becomes available or if a process exceeds its allocated time slice
(quantum). Preemptive scheduling ensures fairness, responsiveness, and prioritization
of tasks.
Round Robin: A process is allocated a fixed time slice (quantum) of CPU time.
When the quantum expires, the process is preempted, and another process is given
Operating System 24
the CPU.
Priority Scheduling: Processes are executed based on their priority levels, with
higher-priority processes preempting lower-priority ones.
Non-Preemptive Scheduling:
Non-preemptive scheduling, also known as cooperative scheduling, allows a process
to continue running until it voluntarily releases the CPU by either blocking (e.g., for I/O)
or completing its execution. The operating system does not forcibly interrupt a running
process to allocate the CPU to another process. Instead, it relies on the cooperation of
processes.
First-Come, First-Served (FCFS): Processes are executed in the order they arrive,
and they continue to run without preemption until they complete their execution or
block.
Operating System 25
Shortest Job Next (SJN) or Shortest Job First (SJF): The process with the
shortest burst time is executed without preemption, allowing it to complete before
other processes are given the CPU.
Priorities in Scheduling:
In the context of processor scheduling, priorities play a crucial role in determining the
order in which processes or threads are granted access to the CPU. Prioritization is
used to manage the execution of processes based on their relative importance or
urgency. Let's delve into the concept of priorities in scheduling:
1. Importance of Priorities:
Priorities are assigned to processes or threads to reflect their significance within the
system. High-priority processes are given preference in CPU allocation, ensuring that
critical tasks are executed promptly. Here's how priorities are used and their
significance:
2. Priority Levels:
Priority levels can vary from system to system, with different operating systems using
distinct scales to represent priorities. Common approaches include:
Operating System 26
Absolute Priorities: In some systems, priorities are assigned as absolute values,
with higher numbers indicating higher priority. For example, a process with priority
10 is more important than a process with priority 5.
Relative Priorities: In other systems, priorities are assigned relative to each other,
with lower numbers indicating higher priority. A process with priority 1 is more
important than a process with priority 5. This approach is sometimes used to avoid
confusion.
Priority Ranges: Some systems categorize processes into priority ranges, such as
"high," "medium," and "low." Each range represents a group of priorities, simplifying
the priority assignment process.
4. Priority Inversion:
Various scheduling algorithms utilize priorities as a key criterion for making scheduling
decisions. Common priority-based scheduling policies include:
Priority Scheduling: This policy allocates CPU time to processes based on their
assigned priorities. Higher-priority processes are executed before lower-priority
ones.
Operating System 27
Multilevel Queue Scheduling: Processes are categorized into multiple priority
queues, each with its own priority level. The scheduler selects the queue to serve,
and within the queue, processes are scheduled based on their priorities.
To avoid priority inversion issues in real-time systems, priority inheritance and priority
ceiling protocols are employed. Priority inheritance temporarily boosts the priority of a
lower-priority process that holds a resource required by a higher-priority process.
Priority ceiling ensures that a resource is held by the highest-priority task accessing it.
In summary, priorities are vital for managing process execution in scheduling. They
determine the order in which processes or threads are granted access to the CPU and
play a significant role in ensuring system responsiveness, resource allocation, and
fairness. Assigning and managing priorities effectively is crucial in optimizing system
performance and meeting specific application requirements.
Scheduling Objectives:
Scheduling objectives specify the high-level goals that a scheduling algorithm aims to
achieve. These objectives guide the scheduler in making decisions about which process
or thread to execute next. Common scheduling objectives include:
1. Fairness: Fairness in scheduling ensures that each process or thread gets a fair
share of the CPU's time. The objective is to distribute CPU time equitably among
competing processes, preventing any single process from monopolizing resources.
7. Response Time: Response time is the time taken for a process to start executing
after it enters the ready queue. Minimizing response time is essential for ensuring
rapid task initiation.
Scheduling Criteria:
Scheduling criteria are specific parameters and attributes used to make scheduling
decisions. These criteria help the scheduler compare and prioritize processes based on
measurable factors. Common scheduling criteria include:
1. Burst Time: Burst time is the time a process spends running on the CPU before it
either blocks (for I/O or other reasons) or terminates. Shorter burst times often
indicate processes that can complete quickly.
3. Waiting Time: Waiting time is the total time a process has spent waiting in the
ready queue before gaining access to the CPU. Reducing waiting time is often a
scheduling goal to improve system responsiveness.
7. I/O and CPU Burst Times: Different processes may have varying I/O burst times
and CPU burst times. Schedulers may prioritize I/O-bound processes to improve
overall system efficiency.
8. Process Age and Aging: Aging is a dynamic criterion that increases the priority of
processes in the ready queue if they have been waiting for a long time. Aging helps
prevent processes from being indefinitely starved.
Scheduling algorithms
https://www.youtube.com/watch?v=zFnrUVqtiOY&list=PLxCzCOWd7aiGz9donH
RrE9I3Mwn6XdP8p&index=14&pp=iAQB
Characteristics:
Easy to implement.
May lead to poor CPU utilization if long processes arrive first (the "convoy
effect").
Example: Imagine three processes arriving in the order P1, P2, P3. They execute
sequentially, with P1 running to completion before P2 and P3 start.
Description: SJN or SJF scheduling selects the process with the shortest burst
time for execution. This minimizes average waiting time.
Characteristics:
Requires knowledge of the burst times, which is often not available in practice.
Example: If processes P1, P2, and P3 have burst times of 5, 3, and 7, respectively,
SJN would execute P2, then P1, and finally P3.
Characteristics:
Example: If processes P1, P2, and P3 each get a time quantum of 2, they take
turns executing in a cyclic manner, like P1 -> P2 -> P3 -> P1 -> P2 -> ...
4. Priority Scheduling:
Operating System 31
Description: Priority scheduling allocates the CPU to processes based on their
priority levels. Higher-priority processes are executed before lower-priority ones.
Characteristics:
Example: If P1 has higher priority than P2, the scheduler executes P1 before P2.
Description: In this approach, processes are divided into multiple priority queues,
each with its own scheduling algorithm. Each queue may have different priority
levels and scheduling policies.
Characteristics:
Characteristics:
7. Lottery Scheduling:
Operating System 32
is granted access to the CPU.
Characteristics:
Example: If a process holds 10 out of 100 total tickets, it has a 10% chance of
being selected.
8. Real-Time Scheduling:
Characteristics:
Example: In a hard real-time system for controlling a medical device, the scheduler
ensures that critical control tasks meet their timing requirements.
These are some of the most common scheduling algorithms. The choice of scheduling
algorithm depends on the specific requirements of the system, the nature of the
workloads, and the desired system behavior. The selection of an appropriate scheduling
algorithm is crucial for optimizing system performance and meeting the objectives and
criteria set for scheduling.
Demand Scheduling:
Demand scheduling, also known as event-driven scheduling or on-demand
scheduling, is a scheduling mechanism where a process requests CPU time when it
needs it, rather than being allocated a fixed time slice or being scheduled by a pre-
defined policy. This approach is often used in interactive and event-driven systems.
Here's how demand scheduling works:
Operating System 33
input, device signals, or other events that require immediate attention.
Examples: User interactions with graphical user interfaces (GUIs) often trigger
demand scheduling. When a user clicks a button or enters text, the associated
event handler is executed immediately.
Real-Time Scheduling:
Real-time scheduling is used in systems with time-critical tasks where meeting specific
deadlines is crucial. These systems include applications like avionics, industrial control
systems, medical devices, and telecommunications. Real-time scheduling is classified
into two categories: hard real-time and soft real-time.
The scheduler prioritizes tasks based on their importance and ensures that
high-priority tasks are executed before lower-priority ones. This may involve
preemptive scheduling.
In soft real-time systems, occasional deadline misses are tolerable, and the
system can recover. While meeting deadlines is still a priority, there is some
Operating System 34
flexibility.
The scheduler aims to maximize the number of deadlines met and minimize the
number of missed deadlines. Tasks are often assigned priorities based on their
timing constraints.
Real-time scheduling is challenging due to the need for precise timing and meeting
stringent deadlines. Schedulers in real-time systems often employ priority-based
algorithms, rate-monotonic scheduling, earliest deadline first (EDF), and other
techniques to ensure that critical tasks are executed on time and that system
performance is predictable and reliable.
Unit 2
Process Synchronization: Mutual Exclusion
Mutual Exclusion:
Operating System 35
a shared resource at a time, preventing concurrent access and potential data
corruption or race conditions.
Key Considerations:
If another process holds the lock, the requesting process must wait until the lock
is released.
Once a process exits the critical section, it releases the lock, allowing another
process to enter.
1. Locks:
Mutex (Mutual Exclusion) locks are a popular mechanism for achieving mutual
exclusion.
A process or thread acquires the lock before entering a critical section and
releases it upon exiting.
Locks ensure that only one thread can hold the lock at a time.
2. Semaphores:
Semaphores are more versatile synchronization objects, but they can also be
used to implement mutual exclusion.
3. Atomic Operations:
Operating System 36
In some cases, atomic operations provided by the hardware or programming
language can be used to implement mutual exclusion.
Prevents race conditions: Ensures that only one process can access critical
sections, preventing conflicts and data corruption.
Promotes data consistency: Mutual exclusion helps maintain the integrity of shared
data by preventing concurrent writes or reads that could lead to inconsistency.
Deadlock: Care must be taken to avoid situations where processes wait indefinitely
for a lock that will not be released.
1. Locks (Mutexes):
Operating System 37
Description: Locks, also known as mutexes (short for mutual exclusion), are one of
the most widely used software solutions for achieving mutual exclusion.
2. Semaphores:
4. Peterson's Algorithm:
Operating System 38
Description: Peterson's algorithm is a classic software-based solution for achieving
mutual exclusion between two processes.
How It Works: Processes take numbers as "tickets" upon entering a queue. The
process with the smallest ticket number gets access to the critical section. If multiple
processes request access simultaneously, the one with the lowest ticket number
enters first.
These software solutions to the mutual exclusion problem provide mechanisms for
controlling access to critical sections of code and shared resources in concurrent
programs. The choice of which solution to use depends on the programming language,
the platform, and the specific requirements of the application.
Operating System 39
predetermined value (usually 1). It returns the previous value.
How It Works: To achieve mutual exclusion, processes or threads can use TAS to
acquire a lock. If the previous value is 0, it means the lock was successfully
acquired, and the process can enter the critical section. If the previous value is 1,
the process is blocked until the lock is released.
Drawbacks: The availability and behavior of CAS may vary across different
hardware architectures.
Benefits: It's useful for implementing mechanisms like Lamport's Bakery algorithm
for mutual exclusion.
Operating System 40
Drawbacks: It may not be as widely supported as CAS or TAS on all hardware
platforms.
4. Locking Instructions:
Description: Some modern CPUs provide specific instructions for locking memory
regions, ensuring atomic access.
Benefits: Locking instructions are highly efficient and eliminate the need for busy-
waiting or spinlocks.
Semaphores
Semaphores are a synchronization mechanism used in concurrent programming to
control access to shared resources or coordinate the execution of multiple processes or
threads. They were introduced by Edsger Dijkstra in 1965 and have become an
essential tool in managing mutual exclusion and synchronization. Semaphores are
particularly valuable in situations where mutual exclusion and coordination are required.
Here's an overview of semaphores:
1. Binary Semaphores:
Operating System 41
Wait (P) Operation: Decrements the semaphore value. If the value is already 0,
the calling process or thread is blocked until another process increments the
semaphore (release operation).
2. Counting Semaphores:
Wait (P) Operation: Decrements the semaphore value. If the value is already 0,
the calling process or thread is blocked until another process increments the
semaphore (release operation).
3. Semaphore Operations:
Wait (P) Operation: The "P" operation (short for "proberen," which means "to test"
in Dutch) is used to request access to a semaphore. If the semaphore's value is
greater than zero, it is decremented, and the process continues execution. If the
value is zero, the process is blocked.
Signal (V) Operation: The "V" operation (short for "verhogen," which means "to
increment" in Dutch) is used to release a semaphore. It increments the semaphore's
value. If there are any blocked processes or threads waiting for the semaphore, one
of them is unblocked.
Mutual Exclusion: Binary semaphores can be used to ensure that only one
process or thread accesses a critical section at a time.
Operating System 42
consumers.
Resource Pool Management: Counting semaphores can control the allocation and
release of resources like network connections, database connections, or threads in
a thread pool.
5. Benefits of Semaphores:
They can be used to handle various synchronization scenarios, from simple mutual
exclusion to more intricate coordination problems.
6. Drawbacks of Semaphores:
Operating System 43
Critical Section Problems
Critical section problems refer to a class of synchronization issues in concurrent
programming where multiple processes or threads attempt to access shared resources,
data, or code, and conflicts can occur. The goal is to ensure that only one process at a
time can execute a critical section of code or access a shared resource to prevent data
corruption, race conditions, and other synchronization problems. Here are some key
aspects of critical section problems:
1. Critical Section:
Mutual Exclusion: Only one process can execute the critical section at any
given time.
Bounded Waiting: There exists a bound on the number of times that other
processes are allowed to enter their critical sections after a process has made a
Operating System 44
request to enter its critical section and before that request is granted.
Locks: Mutexes (mutual exclusion locks) are used to ensure that only one
process or thread can hold the lock at a time, providing mutual exclusion.
Condition Variables: Condition variables are used to signal and wait for
specific conditions to be met before accessing critical sections, often in
combination with locks.
Starvation can also occur when processes or threads are unfairly treated in
resource allocation, resulting in some processes being delayed indefinitely in
entering their critical sections.
In summary, critical section problems are central to ensuring the orderly execution of
concurrent programs. By applying synchronization mechanisms and algorithms that
satisfy the requirements of mutual exclusion, progress, and bounded waiting,
Operating System 45
developers can address these issues and prevent synchronization problems such as
data corruption, race conditions, and deadlocks.
Each philosopher thinks and eats. To eat, a philosopher must pick up both the left
and right forks.
Philosophers can only pick up one fork at a time, and they can only eat when they
have both forks.
The goal is to design a solution that allows the philosophers to eat without leading to
deadlocks or other synchronization issues.
Solution:
Several solutions can address the Dining Philosophers problem, ensuring that all
philosophers can eat while avoiding deadlocks. One common solution involves using
semaphores and mutex locks:
2. Pick up forks: To eat, a philosopher must pick up both the left and right forks. To
do this, they acquire the semaphores (forks). If both forks are available, the
philosopher picks them up.
4. Put down forks: After eating, the philosopher releases the forks (releases the
semaphores) for others to use.
Care must be taken to ensure that the critical section (the process of picking up and
putting down forks) is properly synchronized with mutex locks to avoid race
conditions.
Balancing the use of forks is important to ensure that all philosophers get a chance
to eat.
There is one barber and a waiting room with limited capacity for customers.
Customers enter the barber shop and either find an available seat in the waiting
room or leave if it's full.
The barber serves one customer at a time. If there are no customers, the barber
sleeps. When a customer arrives, they wake the barber.
The goal is to design a solution that simulates this behavior while ensuring that
customers are served in an orderly manner.
Solution:
Solving the Barber Shop problem requires coordination and synchronization to manage
customers and the barber's activities. One common solution involves using semaphores
and mutex locks:
A semaphore is used to represent the number of available seats in the waiting room.
Initially, it's set to the maximum number of seats.
A mutex lock is used to control access to shared resources, such as the waiting
room and the barber's chair.
Operating System 47
1. If a seat is available in the waiting room, they take a seat. If all seats are
occupied, they leave.
The coordination between customers and the barber, as well as the management of
the barber's sleeping state, is essential for a successful solution.
Memory Organization
Memory organization is a fundamental concept in computer systems and computer
architecture. It refers to how a computer's memory is structured, managed, and used to
store and retrieve data and instructions. Memory organization plays a critical role in the
Operating System 48
performance and functionality of a computer system. Here's an overview of memory
organization:
1. Memory Hierarchy:
Registers: These are the smallest, fastest, and most closely located to the
CPU. Registers store data that the CPU is actively processing.
Main Memory (RAM): RAM is the primary volatile memory used to store data
and instructions that the CPU needs to access quickly during program
execution.
2. Address Space:
The size of the address space is determined by the number of addressable memory
locations and the number of bits used to represent memory addresses. For
example, a 32-bit system can address 2^32 (4,294,967,296) memory locations.
The address space is divided into various regions for different purposes, including
program memory, data storage, and system memory.
3. Memory Units:
Memory is typically organized into smaller units, such as bytes. Each memory unit is
identified by a unique address. In modern systems, the basic unit of data storage is
the byte, which is composed of 8 bits.
Operating System 49
4. Memory Types:
Memory can be categorized into different types based on its characteristics and
usage. Common memory types include:
RAM (Random Access Memory): RAM is used for temporary data storage
during program execution. It provides fast read and write access.
Cache Memory: Cache memory is a small but extremely fast memory used to
store frequently accessed data.
5. Memory Management:
6. Memory Access:
Memory access involves reading data from or writing data to memory. The speed
and efficiency of memory access are critical for the overall performance of a
computer system.
7. Address Mapping:
8. Memory Protection:
Operating System 50
Memory organization is a complex and essential aspect of computer systems,
influencing both their performance and functionality. Effective memory organization
ensures efficient data storage and retrieval, supports multitasking, and plays a vital role
in the overall user experience. Understanding memory organization is crucial for
computer architects, software developers, and system administrators.
Memory Hierarchy
The memory hierarchy is a key concept in computer architecture and design, outlining
the various levels of memory in a computer system, each with distinct characteristics
and purposes. The memory hierarchy is structured in a way that optimizes data access
speed and storage capacity while managing costs. Here's an overview of the memory
hierarchy:
1. Registers:
Description: Registers are the smallest and fastest storage units in the memory
hierarchy. They are located within the CPU itself.
Purpose: Registers store data and instructions that the CPU is actively processing.
They are used for rapid data access and temporary storage during computation.
Characteristics: Registers have very fast access times, but their capacity is
extremely limited. They typically store small amounts of data, such as CPU registers
like the program counter and general-purpose registers.
2. Cache Memory:
Purpose: Cache memory serves as a buffer for frequently accessed data and
instructions. It helps improve the CPU's speed and performance by reducing the
time it takes to access data.
Characteristics: Cache memory is faster than main memory but has limited
capacity. It operates on the principle of temporal and spatial locality, storing
frequently accessed data to reduce the need for slower access to main memory.
Operating System 51
than the previous one.
Purpose: RAM stores data and instructions that the CPU needs to access quickly
during program execution. It serves as a bridge between the high-speed cache and
the long-term storage of secondary storage devices.
Description: Secondary storage devices include hard disk drives (HDDs) and solid-
state drives (SSDs).
5. Tertiary Storage:
Purpose: Tertiary storage is used for archival purposes and long-term data backup.
It is slower to access than secondary storage.
6. Remote Storage:
Purpose: Remote storage is used for data backup, sharing, and access from
multiple devices. It provides redundancy and data availability from various locations.
Operating System 52
Characteristics: Access to remote storage depends on network speed and latency.
It offers scalable and distributed storage solutions.
The memory hierarchy is designed to balance the trade-offs between speed, capacity,
and cost. The hierarchy allows the CPU to access data as quickly as possible by
prioritizing the use of the smallest, fastest, and most expensive storage at the top of the
hierarchy (registers and cache), while also providing larger, slower, and more cost-
effective storage options lower down in the hierarchy (main memory, secondary storage,
tertiary storage, and remote storage). This structure is essential for optimizing the
performance of computer systems while efficiently managing data storage.
Disadvantages: It limits the use of memory, as programs must fit within a single
contiguous block. Fragmentation issues can arise, leading to wasted memory
space.
2. Partitioned Allocation:
3. Paging:
Description: Paging divides physical memory and virtual memory into fixed-size
blocks called pages. Similarly, programs are divided into fixed-size blocks called
frames. The OS manages a page table to map virtual pages to physical frames.
4. Segmentation:
Disadvantages: May still suffer from fragmentation, both internal and external.
Segment management can be complex.
5. Virtual Memory:
Operating System 54
Description: Virtual memory extends the available physical memory by using disk
storage as a "backing store." Only a portion of a program is loaded into physical
memory when it's needed, while the rest resides on disk.
Disadvantages: Disk access is slower than physical memory, which can lead to
performance issues when swapping data between memory and disk.
6. Demand Paging:
Description: Demand paging is a variant of virtual memory that brings pages into
physical memory only when they are needed (on-demand).
Disadvantages: May incur page faults (performance hits) when a required page is
not in physical memory.
7. Thrashing:
Description: Thrashing occurs when the system spends more time swapping
pages between memory and disk than executing processes. It is a performance
bottleneck caused by excessive page faults.
8. Swapping:
9. Compaction:
Operating System 55
Description: Compaction is a technique used to reduce external fragmentation. It
involves shifting memory contents to eliminate small gaps between allocated
memory blocks.
Operating System 56
5. Limited Address Space: Contiguous allocation may limit the address space
available for a single process, as the size of a process cannot exceed the size of the
largest available contiguous block.
5. Address Space Flexibility: Non-contiguous allocation allows for more flexible use
of the address space, as it can accommodate larger processes than the available
contiguous blocks.
Comparison:
Operating System 57
Address Space: Non-contiguous allocation offers more flexibility for processes to
grow and use larger address spaces.
The choice between contiguous and non-contiguous memory allocation depends on the
specific requirements of the system, including the need for memory efficiency, address
space flexibility, and the ability to manage external fragmentation.
1. Fixed Partitioning:
How It Works: Each partition is of a predetermined size, and processes are loaded
into these partitions. If a process's size is smaller than the partition, it is allocated to
the partition. If it is larger, it must wait for a partition of sufficient size.
2. Dynamic Partitioning:
Operating System 58
How It Works: When a process is loaded, it is allocated the exact amount of
memory it needs, and the partition size can vary. As processes enter and exit the
system, partitions are created and destroyed as needed.
3. Buddy System:
How It Works: Memory is split into blocks of sizes like 1 KB, 2 KB, 4 KB, and so on.
When a process requests memory, it is allocated a block that matches or exceeds
its size, and any excess space is divided recursively until an exact match is found.
4. Paging:
Description: Paging divides both physical and virtual memory into fixed-size blocks
called pages.
How It Works: Processes are divided into fixed-size blocks called frames. The
operating system maintains a page table to map virtual pages to physical frames.
5. Segmentation:
Operating System 59
How It Works: Memory is divided into segments like code, data, and stack.
Processes can request additional memory segments as needed.
Disadvantages: May still suffer from fragmentation, both internal and external.
Segment management can be complex.
6. Swapping:
How It Works: Processes are temporarily moved to secondary storage when they
are not actively running. They are brought back into memory when needed.
1. Definition: The logical address space, also known as virtual address space, is the
set of addresses generated by a program during its execution. These addresses are
typically generated by the CPU as the program runs and are used by the program to
reference memory locations.
Operating System 60
2. Visibility: Logical addresses are visible to the application or program running on the
computer. The program uses logical addresses when accessing data and
instructions.
3. Size: The logical address space is often larger than the physical address space. It
can be as large as the range of values that can be held by the data type used to
represent addresses (e.g., 32-bit or 64-bit).
5. Dynamic: Logical addresses can be dynamic and change as the program executes.
For instance, in virtual memory systems, the program may generate logical
addresses that do not correspond directly to physical memory locations.
1. Definition: The physical address space is the set of addresses that directly
correspond to locations in the computer's physical memory hardware (RAM). These
addresses are used by the memory management unit (MMU) to fetch data from or
store data to physical memory chips.
2. Visibility: Physical addresses are not visible to the application or program. The
program running on the computer deals with logical addresses, and the translation
to physical addresses is handled by the operating system and hardware.
3. Size: The physical address space is limited by the amount of physical RAM installed
in the computer. It typically ranges from a few gigabytes to terabytes, depending on
the system's hardware.
5. Static: Physical addresses are static and do not change during program execution.
They map directly to physical memory locations.
Operating System 61
6. Used by Memory Hardware: Physical addresses are used by the memory
management unit (MMU) to access data stored in physical memory chips (RAM).
Address Translation:
The relationship between logical and physical addresses is managed through address
translation. The MMU, which is part of the CPU, translates logical addresses generated
by the program into physical addresses that are used to access memory. This
translation is a crucial part of virtual memory systems, allowing programs to operate with
a larger logical address space than the available physical memory.
In summary, logical and physical address spaces serve different purposes in memory
management. Logical addresses are generated by programs, provide flexibility, and are
subject to protection mechanisms. Physical addresses correspond directly to physical
memory locations and are managed by the hardware and operating system. Address
translation bridges the gap between these two address spaces in virtual memory
systems.
Swapping
Swapping is a memory management technique used in computer systems to efficiently
utilize physical memory (RAM) and provide the illusion of having more memory than is
physically available. It involves moving data between the RAM and secondary storage
(usually a hard disk or SSD) to ensure that the most actively used processes and data
are in RAM, while less active or unused portions are temporarily stored on the disk.
Here's how swapping works and its key aspects:
Operating System 62
3. Data Transfer: When a page is selected for swapping, it is moved to secondary
storage, freeing up space in physical memory. If a page needs to be brought into
physical memory, the operating system retrieves it from secondary storage and
loads it into an available memory location.
4. Disk Swap Space: The portion of secondary storage used to temporarily store
swapped-out pages is called the "swap space." This space must be large enough to
accommodate the pages that are not in physical memory.
2. Page Faults: The frequency of page faults is a key factor in determining when and
how often swapping occurs. A system with a high rate of page faults may
experience more swapping.
Paging
Paging is a memory management technique used in computer systems, particularly in
virtual memory systems, to efficiently manage and access memory. It involves dividing
both physical and virtual memory into fixed-size blocks called pages. Paging allows for
several benefits, including efficient memory allocation, memory protection, and the
illusion of a larger address space. Here's an overview of how paging works and its key
aspects:
How Paging Works:
1. Page Size: Paging divides memory into fixed-size blocks known as pages. The
page size is typically a power of 2, like 4 KB or 4 MB. Both the physical memory
(RAM) and virtual memory (address space) are divided into pages.
3. Page Table: The page table is a data structure maintained by the operating system.
It contains entries that map virtual page numbers to physical frame numbers. Each
process has its own page table, which is used for address translation. The operating
system is responsible for creating and managing these page tables.
4. Page Faults: If a program tries to access a page that is not in physical memory (a
page fault occurs), the operating system must fetch the required page from
secondary storage (usually a hard disk) into an available physical frame. This
process is known as page swapping.
Operating System 64
1. Memory Management: Paging efficiently manages memory allocation by dividing it
into fixed-size pages. This eliminates external fragmentation, as pages can be
allocated and deallocated independently of one another.
2. Address Space: Paging provides the illusion of a large address space for each
process. The actual physical memory can be smaller than the virtual address space,
allowing programs to access more memory than is physically available.
3. Page Replacement: When physical memory is full, the operating system uses a
page replacement algorithm (e.g., LRU, FIFO) to determine which page to swap out
to secondary storage to make room for a new page. This is crucial for maintaining
the illusion of a larger address space.
4. Security and Isolation: Paging allows for memory protection and isolation. Each
process has its own address space, and the page table ensures that processes
cannot access each other's memory.
Operating System 65
Segmentation
Segmentation is a memory management technique used in computer systems to divide
the memory into logical segments, each of which can be assigned specific attributes
and permissions. Segmentation provides a more flexible and structured approach to
memory organization compared to other techniques like contiguous memory allocation.
Here's an overview of how segmentation works and its key aspects:
5. Complexity: Managing segments and their attributes can be more complex than
traditional memory allocation methods. The operating system must maintain
segment tables and perform address translations.
Operating System 68
efficient memory management scheme. When segmentation and paging are used
together with demand paging, it provides benefits in terms of memory allocation,
protection, and the illusion of a larger address space. Here's an explanation of how
these techniques work together with a focus on demand paging:
2. Paging: Paging divides both physical and virtual memory into fixed-size blocks
called pages. Paging eliminates external fragmentation and allows for the efficient
allocation and deallocation of memory.
Demand Paging:
3. Page Table: The operating system maintains page tables for each segment. These
page tables map virtual page numbers to physical frame numbers. Each segment
has its page table.
4. Demand Paging: Pages are not loaded into physical memory at the start of
program execution. Instead, they are loaded into memory on-demand when they are
accessed by the program. When a page fault occurs (i.e., a requested page is not in
physical memory), the page is brought from secondary storage (e.g., a hard disk) to
physical memory.
Operating System 69
5. Performance Optimization: To optimize demand paging, the system may use
various page replacement algorithms (e.g., LRU, FIFO) to determine which pages
should be swapped out to secondary storage to make room for the incoming page.
6. Security and Protection: Segmentation and paging together allow for strong
memory protection and isolation. Each segment/page can have specific attributes
and permissions, and unauthorized memory access results in segmentation and
paging faults.
8. Operating System Control: The operating system manages the page tables for
each segment, performs address translations, and handles page faults. It is
responsible for setting up and managing segments and pages.
The combination of segmentation and paging with demand paging allows for a more
flexible, efficient, and secure memory management scheme. It's suitable for multitasking
environments where multiple processes run concurrently, and memory protection is
crucial. This approach ensures that processes can have a structured and isolated
memory layout while benefiting from the efficient use of physical memory through
demand paging.
1. Page Table: In a virtual memory system, a page table is used to map logical pages
in a program's address space to physical frames in RAM.
Operating System 70
2. Page Fault: When a program accesses a page that is not currently in physical
memory, a page fault occurs. This means the required page must be brought in from
secondary storage (e.g., a hard disk) into an available physical frame.
3. Full Memory: When physical memory is fully occupied, and a new page needs to
be brought in, an existing page must be evicted (swapped out) to make room for the
new page.
Page-Replacement Algorithms:
Several page-replacement algorithms have been developed to determine which page
should be replaced. These algorithms have different characteristics, advantages, and
disadvantages. Some common page-replacement algorithms include:
2. LRU (Least Recently Used): LRU replaces the page that has not been used for the
longest time. It requires maintaining a linked list or a counter for each page to track
their usage history. While it provides better performance, it can be complex to
implement efficiently.
3. Optimal: The optimal algorithm selects the page that will not be used for the longest
time in the future. This algorithm provides the best possible performance but is not
practical in real systems because it requires knowledge of future page accesses,
which is impossible to predict.
4. LFU (Least Frequently Used): LFU replaces the page that has been used the least
number of times. It tracks the usage count of each page. LFU can be efficient in
some scenarios but may not always provide the best results.
Operating System 71
6. Clock (or Second-Chance): The clock algorithm is a simplified version of the
second-chance algorithm. It uses a circular list of pages and provides a second
chance to pages before replacement.
7. NRU (Not Recently Used): NRU divides pages into four categories (based on the
recent usage and modification bits), and it replaces a page randomly from the
lowest non-empty category.
8. LFU (Least Frequently Used): This algorithm replaces the page with the lowest
usage count. It aims to keep the pages that are accessed most frequently in
memory.
9. MFU (Most Frequently Used): MFU replaces the page that has the highest usage
count. It attempts to keep the pages that are most heavily used in memory.
The choice of which page-replacement algorithm to use depends on the specific system
and its performance requirements. Each algorithm has its own trade-offs in terms of
complexity and efficiency. The selection of an appropriate algorithm can significantly
impact system performance, especially in virtual memory systems where page
replacement is a common occurrence.
2. Support for Large Address Spaces: Demand paging makes it feasible to support
programs with larger address spaces than the available physical memory. This can
be crucial for running memory-intensive applications.
Operating System 72
3. Quick Program Start: Processes can start running quickly because they don't need
to load their entire code and data into memory before execution. Only the initially
needed pages are loaded on-demand.
Challenges:
1. Page Faults: A major factor affecting the performance of demand paging is the
frequency of page faults. Frequent page faults, especially when combined with slow
disk I/O operations, can degrade system performance.
3. Disk I/O Latency: The performance of demand paging is highly sensitive to the
speed of secondary storage (e.g., hard disks or SSDs). Slow disk I/O can lead to
significant delays in page retrieval and swapping, negatively impacting performance.
2. Page Size: The choice of page size can affect the granularity of page swaps.
Smaller pages reduce internal fragmentation but may lead to more frequent page
faults.
4. Memory Size: Increasing physical memory can reduce the frequency of page faults
because more pages can be kept in RAM. Adequate RAM is essential for efficient
Operating System 73
demand paging.
5. Tuning: System administrators can fine-tune the operating system's virtual memory
settings to strike a balance between performance and efficient memory use.
Thrashing
Thrashing is a term used in the context of computer systems and memory management
to describe a situation where the system is excessively swapping data between physical
memory (RAM) and secondary storage (e.g., hard disk or SSD). It occurs when the
demand for memory by processes exceeds the available physical memory, leading to a
constant cycle of page swapping. Thrashing significantly degrades system performance
and can lead to a "death spiral" where the system becomes virtually unresponsive.
Here's a more detailed explanation of thrashing:
Causes of Thrashing:
3. High Page-Fault Rate: A high rate of page faults, caused by processes frequently
accessing pages that are not in physical memory, can trigger thrashing. Frequent
page faults result in continuous disk I/O operations, further reducing system
performance.
Operating System 74
Characteristics of Thrashing:
3. Low CPU Utilization: Paradoxically, during thrashing, CPU utilization is often low
because the CPU is not actively processing tasks. Instead, it is mostly waiting for
pages to be swapped in or out of memory.
Operating System 75
memory management, and effective monitoring to prevent its occurrence.
Overlay Concepts:
Operating System 76
2. Overlay Manager: An overlay manager is a program or system component
responsible for managing overlays. It loads and unloads overlays into physical
memory as needed during program execution.
3. Overlay Switching: As the program runs, the overlay manager switches between
different overlays, making only one overlay's code and data available in physical
memory at any given time. The system maintains an overlay table that keeps track
of which overlay is currently in use.
Comparison:
Demand Segmentation and Overlay are techniques used for managing memory in
systems with limited physical memory.
Overlay programming, on the other hand, splits a program into separate overlays,
with an overlay manager responsible for swapping them in and out of physical
memory.
In modern computer systems, demand segmentation is less commonly used due to the
availability of larger amounts of physical memory and more sophisticated memory
management techniques. Overlay programming is largely obsolete in modern systems,
as contemporary hardware and software can efficiently handle memory constraints
without the need for overlays.
Operating System 77
made by yashs using chatgpt so content maybe wrong :)
updated version here: https://yashnote.notion.site/Operating-System-
6d1a23bfc9c74eaba2fbab05b10c86ce?pvs=4
Operating System 78