OS Notes
OS Notes
Operating System
What is the main purpose of an operating
system Discuss different types.
The main purpose of an operating system (OS) is to manage and control the
hardware and software resources of a computer system. It acts as an intermediary
between the user and the computer hardware, providing a convenient and
efficient environment for executing programs and utilizing system resources.
Operating System 1
5. User Interface: The OS provides a user-friendly interface that allows users to
interact with the computer system. It can include command-line interfaces,
graphical user interfaces (GUIs), or other specialized interfaces.
2. Single-User, Multi-Tasking:
Operating systems like Windows and macOS support multiple tasks running
concurrently on a single user interface. They allow users to switch between
tasks and provide multitasking capabilities. Examples: Windows, macOS,
Linux.
3. Multi-User:
Multi-user operating systems, such as Unix/Linux and Windows Server,
support multiple users accessing the system simultaneously. They provide
features like user management, resource sharing, and secure access control
for multiple users.
4. Batch OS:
Batch OS processes a large volume of similar jobs in batches without user
interaction. It executes jobs sequentially, commonly used in mainframes and
early systems. Examples include IBM's OS/360 and Job Control Language
(JCL).
Operating System 2
6. Network Operating System:
Network OS provides network services and manages resources for distributed
network environments. It facilitates file sharing, printer access, and network
communication. Examples: Novell NetWare, Windows Server, Linux with
networking capabilities.
These are just a few examples of operating system types, and there are many
variations and specialized operating systems catering to specific requirements
and platforms.
Kernel
The kernel, in the context of operating systems, is the central component that acts
as the core of the operating system. It is responsible for managing system
resources, providing essential services, and serving as an intermediary between
Operating System 3
software applications and the underlying hardware. The kernel performs tasks like
process management, memory management, device management, and
scheduling. It provides a bridge between the hardware and software, enabling
applications to run and interact with the system effectively.
Monolithic Kernel
A monolithic kernel is a type of kernel architecture in which the entire operating
system runs as a single, unified kernel in kernel mode. In a monolithic kernel, all
operating system services, device drivers, and core functionalities are integrated
into a single address space. This design allows for efficient and direct
communication between components but can make the kernel larger and more
complex.
In a monolithic kernel, device drivers, file systems, network protocols, and other
functionalities are part of the kernel itself, residing in kernel space. While this
architecture provides good performance due to direct communication between
components, it also makes the system more vulnerable to crashes or instability
since errors in any part of the kernel can affect the entire system.
Process:
A process, on the other hand, is an instance of a program that is being executed. It
is a dynamic entity with its own memory space, execution context, and resources.
A process represents an active program in execution, including its current state,
program counter, registers, stack, and allocated system resources. Each process
Operating System 4
runs independently of other processes and is managed by the operating system.
Processes provide isolation and protection, ensuring that one process does not
interfere with the execution of another process.
Thread:
A thread is a lightweight unit of execution within a process. It represents a single
sequence of instructions that can be scheduled and executed independently.
Multiple threads can exist within a single process, sharing the same memory
space and resources. Threads within the same process can communicate and
cooperate with each other more efficiently compared to separate processes.
Threads provide concurrency, enabling parallel execution of multiple tasks within
a program.
Batch Processes:
Batch processes are non-interactive processes that execute a series of tasks
without requiring user intervention. They are typically used for background tasks
and automated processing of large volumes of data. Examples include data
processing jobs, system backups, and report generation.
Real-Time Processes:
Real-time processes have strict timing requirements, where response time and
task completion time are critical. They are used in time-sensitive systems such as
control systems, robotics, and signal processing. Real-time processes can be
further classified into hard real-time (strict deadlines) and soft real-time (flexible
deadlines) processes.
Operating System 5
System Processes:
System processes are essential processes that are responsible for managing and
maintaining the operating system itself. They handle critical tasks such as memory
management, process scheduling, and I/O operations. Examples include the
kernel process, init process (in Unix-like systems), and device drivers.
Daemon Processes:
Daemon processes (short for "disk and execution monitor") are background
processes that run continuously, providing services or performing specific tasks
without direct user interaction. They often operate in the background and are
detached from a terminal session. Examples include web servers, network
services, and automated system maintenance tasks.
Forked Processes:
Forked processes are created by an existing process using the fork() system call.
The new process, known as the child process, is a duplicate of the parent process
but can execute different codes. Forked processes are commonly used for parallel
programming, creating multiple independent instances of a program.
Multi-threaded Processes:
Multi-threaded processes have multiple threads of execution within a single
process. Each thread represents an independent sequence of instructions that
can run concurrently. Multi-threaded processes can improve performance by
parallelizing tasks and sharing resources efficiently.
Zombie Processes:
Zombie processes are terminated processes that have completed their execution
but still have an entry in the process table. They remain in the system until their
exit status is collected by the parent process. Zombie processes do not consume
system resources and are typically handled and reaped by the operating system.
Operating System 6
Virtual Memory:
Virtual memory is a memory management technique used by operating systems to
provide an illusion of having more memory than is physically available. It allows
programs to use more memory than what is physically installed in the computer by
utilizing a combination of RAM (Random Access Memory) and disk space. The
operating system divides the virtual address space of a process into pages, which
are stored in both RAM and disk. When a program references a memory location,
the operating system maps the virtual address to a physical address in RAM or
retrieves it from disk if it's not currently in RAM. Virtual memory enables efficient
memory allocation and allows for running larger programs or multiple programs
concurrently.
Thrashing:
Thrashing refers to a situation in which a computer system spends a significant
amount of time and resources swapping data between the physical memory
(RAM) and the disk, resulting in poor performance. Thrashing occurs when the
system is overwhelmed by excessive memory paging due to a high demand for
more memory than is physically available. This can happen when there are too
many active processes or when the total memory required exceeds the available
RAM. As a result, the system spends more time swapping pages in and out of
memory, leading to frequent disk accesses and slowing down the overall system
performance.
Operating System 7
RAID 0 (Striping):
RAID 0 distributes data across multiple drives without redundancy. It enhances
performance by striping data across drives, allowing for parallel read and write
operations. However, RAID 0 offers no data redundancy or fault tolerance, so the
failure of a single drive can result in data loss.
RAID 1 (Mirroring):
RAID 1 creates an exact copy (mirror) of data on two drives. Data is simultaneously
written to both drives, providing redundancy and fault tolerance. In case of a drive
failure, data can be accessed from the remaining drive. RAID 1 provides data
redundancy but does not offer improved performance or increased storage
capacity.
Operating System 8
RAID 50 (Striping with Distributed Parity across RAID 5
Arrays):
RAID 50 combines striping (RAID 0) and distributed parity (RAID 5) across multiple
RAID 5 arrays. It requires a minimum of six drives and provides a balance of
performance, capacity, and fault tolerance. RAID 50 offers better performance
compared to RAID 5 but requires more drives.
2. Hold and Wait: A process that is already holding one or more resources can
request additional resources while still retaining the ones it already holds. The
process will be in a waiting state until it acquires the requested resources.
When these four conditions are met, a system can enter a deadlock state. It is
important to note that the absence of any of these conditions can prevent
Operating System 9
deadlocks from occurring.
To prevent deadlocks, several techniques can be employed, including resource
scheduling algorithms and deadlock avoidance strategies. Some common
approaches to dealing with deadlocks include resource allocation graphs,
banker's algorithm, deadlock detection, and deadlock recovery methods such as
process termination or resource preemption.
The goal is to identify and resolve deadlocks to ensure the efficient and
continuous operation of a computer system.
External Fragmentation:
External fragmentation occurs when free space in a storage system becomes
scattered or fragmented, making it challenging to allocate contiguous blocks of
space to satisfy larger requests. It happens over time as files or data are created,
modified, and deleted, leading to gaps of free space that are too small to be
effectively utilized. External fragmentation can waste significant amounts of
storage capacity and can negatively impact performance due to increased disk
seek times.
Operating System 10
small, non-contiguous blocks of available space. As a result, it becomes
difficult to allocate larger files or data structures that require contiguous
blocks.
Internal Fragmentation:
Internal fragmentation occurs when allocated space within a storage system or
memory region is larger than the actual data or information it holds. It happens
when storage or memory is allocated in fixed-size blocks or units, and the
allocated space is larger than the size of the data being stored. As a result, there
is wasted space within each allocated block. Internal fragmentation can be
observed in file systems, databases, and memory allocation schemes.
For example, if a file system allocates space in fixed-size blocks and a small file
occupies an entire block, the remaining space within that block is wasted and
represents internal fragmentation. Similarly, in memory allocation, if a program
allocates memory in fixed-size pages, and the actual data or variables within a
page do not fully utilize the entire page, internal fragmentation occurs.
What is spooling?
Spooling stands for "Simultaneous Peripheral Operations On-Line." It is a
computer technique used to improve the efficiency of input/output (I/O)
operations by utilizing a buffer or a temporary storage area.
In spooling, instead of sending data directly between input/output devices (such
as printers, disk drives, or terminals) and the executing program, the data is first
spooled or temporarily stored in a disk or memory buffer. The spooling process
allows the input/output operations to overlap with the execution of other tasks,
thus improving overall system performance.
Operating System 11
1. Data Input: When a user or a process submits a job for printing or other I/O
operation, the data is sent to the spooling system instead of directly to the
output device. This allows the user or process to continue working without
waiting for the operation to complete.
2. Spooling Process: The spooling system receives the data and stores it in a
spool file or buffer on a disk or in memory. The spool file acts as an
intermediate storage location for the data.
4. Output Process: The spooling system sends the data from the spool file to the
output device for processing. This can be done at a later time, allowing the
device to operate at its own speed and freeing up the CPU and other
resources for other tasks.
Error Handling: Spooling systems can handle I/O errors, retry failed
operations, and provide logging or notification of any issues encountered
during the I/O process.
Spooling is commonly used for print spooling, where print jobs are spooled to a
disk or memory buffer before being sent to the printer. However, the concept of
spooling can also be applied to other types of I/O operations, such as disk
spooling or terminal spooling, where data is temporarily stored for later processing
or retrieval.
Operating System 12
What are semaphore and mutex?
Semaphores and mutexes are synchronisation mechanisms used in concurrent
programming to control access to shared resources and coordinate the execution
of multiple threads or processes. While they serve similar purposes, there are
some differences between semaphores and mutexes.
Semaphore:
A semaphore is a signalling mechanism that allows multiple threads or processes
to access a shared resource concurrently. It maintains a count, often called a
"permit" or "value," which determines the number of threads that can access the
resource simultaneously. Semaphores can be used to solve critical section
problems, manage resources with limited capacity, and synchronise activities
among threads or processes.
Operating System 13
Key features of mutexes:
1. Ownership: A mutex can be owned by a single thread or process at a time.
Only the owning thread/process can release the mutex.
Usage:
Semaphores: Semaphores are primarily used to control access to a limited
number of resources or to synchronize activities among multiple threads or
processes. They can be used to solve various synchronization problems, such
as implementing critical sections, managing resource pools, and signaling
events between threads or processes.
Operating System 14
Mutexes: Mutexes are specifically designed to provide mutual exclusion,
ensuring that only one thread or process can access a shared resource at a
time. They are commonly used to protect critical sections of code, which are
sections that must be executed atomically to avoid race conditions and
maintain data consistency.
Permits/Ownership:
Semaphores: Semaphores maintain a counter, often referred to as "permits"
or "values," which represents the number of available resources. Threads or
processes can acquire or release permits from a semaphore, allowing a
certain number of them to access the resource simultaneously.
Mutexes: Mutexes are binary semaphores, meaning they have only two states:
locked or unlocked. They provide exclusive ownership, allowing only one
thread or process to acquire the mutex at any given time. The thread or
process that acquires the mutex becomes the owner and is responsible for
releasing it.
Blocking Behavior:
Semaphores: Acquiring a semaphore can be a blocking or non-blocking
operation, depending on the semaphore implementation and the number of
available permits. If no permits are available, a thread/process attempting to
acquire a semaphore may be blocked until permits become available or
proceed immediately, depending on the implementation.
Operating System 15
Mutexes: Mutexes are specifically designed for mutual exclusion and
protecting critical sections. They provide a simple and efficient mechanism for
ensuring that only one thread/process accesses a shared resource at a time.
Operating System 16
operation, where the process or thread checks the semaphore's state and
continues with other tasks if the semaphore is currently locked.
Operating System 17
4. Synchronization and Coordination: Counting semaphores provide a means of
synchronizing and coordinating access to a set of resources among multiple
processes or threads. They help prevent resource contention, manage
resource availability, and avoid race conditions.
Belady’s Anomaly
Belady's Anomaly, also known as the FIFO anomaly or the anomaly of increasing
the number of page faults, is a phenomenon that can occur in page replacement
algorithms used in virtual memory management. It describes a situation where
increasing the number of available frames in the memory can lead to an increase
in the number of page faults, contrary to the expected behaviour.
In virtual memory systems, page replacement algorithms are used to decide which
pages to evict from physical memory (RAM) when a new page needs to be
brought in. The goal of these algorithms is to minimize the number of page faults,
which occur when a requested page is not found in physical memory and needs to
be retrieved from secondary storage (such as the disk).
Operating System 18
Belady's Anomaly can occur in algorithms that use a page replacement policy
based on the principle of Least Recently Used (LRU) or similar policies. In these
algorithms, pages that are least recently used are selected for eviction when a
page fault occurs. The anomaly arises due to the complex interactions between
the reference patterns of pages and the size of the available memory.
Aging
Aging is a technique used in scheduling algorithms to prevent or mitigate the
effects of starvation. It involves dynamically adjusting the priorities of processes
over time to prevent long-waiting or low-priority processes from being
continuously delayed or starved.
Operating System 19
In aging, as a process waits in the queue or remains unexecuted for a certain
period, its priority gradually increases. By increasing the priority of waiting
processes, aging ensures that lower-priority processes eventually get a chance to
execute, even if they have been preempted by higher-priority processes for an
extended period. This helps to balance fairness and prevent indefinite delays for
low-priority processes.
Aging can be implemented in various scheduling algorithms such as priority-
based scheduling or multi-level feedback queues (MLFQ). It provides a way to
distribute CPU time fairly among processes of different priorities and prevent any
single process from monopolizing system resources for an extended period.
Operating System 20
the system will struggle to keep up with the demand, resulting in increased
page faults and thrashing.
4. Working Set Size Changes: The working set size of a process can change
over time. If the system fails to adapt to these changes and allocate sufficient
memory to processes based on their evolving working sets, it can lead to
thrashing. For instance, if a process suddenly requires a larger working set
due to increased data access, but the system does not allocate the additional
memory, the process may experience frequent page faults and contribute to
thrashing.
Operating System 21
The main purposes and benefits of paging are:
1. Memory Management: Paging allows for flexible memory management by
providing a level of indirection between the logical addresses used by a
process and the physical addresses of memory. It allows processes to utilize a
larger virtual address space than the actual physical memory available,
enabling the execution of larger and more complex programs.
2. Address Space Isolation: Each process has its own virtual address space,
which is isolated from other processes. This provides process-level protection
and prevents one process from accessing or modifying the memory of another
process.
6. Swapping and Page Replacement: Paging also allows for efficient swapping
and page replacement. When physical memory becomes scarce, the
operating system can swap out pages from less active processes to disk,
freeing up memory for more critical or frequently used pages. Page
replacement algorithms determine which pages to evict from memory when a
new page needs to be loaded.
Operating System 22
Demand Paging:
Demand Paging is a memory management technique where pages are loaded into
memory only when they are required, rather than loading the entire program or
process into memory at once. In a demand-paged system, the logical address
space of a process is divided into fixed-sized pages, and only the pages that are
needed for execution are brought into physical memory.
Faster Process Startup: Processes can start quickly since they do not need to
load their entire address space into memory before execution.
When a process attempts to access a page that is not currently in memory (a page
fault), the operating system retrieves the required page from secondary storage
(such as a disk) and loads it into an available memory frame. The page table is
then updated to reflect the new mapping between the logical page and the
physical frame. This technique enables processes to have larger virtual address
spaces than the available physical memory.
Segmentation:
Segmentation is a memory management technique where the logical address
space of a process is divided into variable-sized segments. Each segment
represents a distinct unit of the program, such as the code segment, data
segment, stack segment, etc. Segmentation provides a way to organize and
manage different parts of a program or process.
Operating System 23
management.
Each segment is assigned a base address and a length, and the segment table
stores the mapping between logical segments and their corresponding physical
memory locations. The segmentation approach is often used in combination with
paging to provide a hierarchical and flexible memory management scheme.
Segmentation and paging can be combined in systems that use a two-level
memory hierarchy, where segments are divided into pages. This approach, known
as segmented paging, combines the benefits of both techniques, allowing for
flexible organization and management of memory while efficiently utilizing
available physical memory resources.
Operating System 24
constraints. Hard real-time operating systems typically employ static priority
scheduling algorithms and have fast and predictable response times.
2. Soft Real-Time Operating System: Soft real-time operating systems are used
in applications where meeting all deadlines is desirable but occasional
deadline misses are tolerable. These systems aim to provide a high probability
of meeting timing requirements but do not guarantee it. Soft real-time
operating systems often employ priority-based scheduling algorithms that
allow for some flexibility in meeting deadlines and handling overloads
gracefully.
Each type of RTOS has its own strengths and trade-offs, and the choice depends
on the specific requirements of the real-time application. It is important to select
an RTOS that can meet the timing constraints of the application, provide the
necessary scheduling mechanisms, and offer the required level of determinism
and predictability.
Operating System 25
Main memory and secondary memory are two types of storage devices in a
computer system, but they differ in their characteristics, functionality, and
purpose. Here are the key differences between main memory (also known as
primary memory or RAM) and secondary memory (also known as auxiliary
memory or storage):
Function:
Main Memory: Main memory is the primary storage used by a computer to
temporarily store data that the CPU (Central Processing Unit) actively
accesses during program execution. It holds the operating system,
applications, and data that are currently being processed or used.
Volatility:
Main Memory: Main memory is volatile, meaning its contents are lost when
the computer is powered off or restarted. It is designed for fast read and write
operations to support the immediate needs of the CPU.
Speed:
Main Memory: Main memory provides fast access to data and instructions
needed by the CPU. It is directly accessible by the CPU, resulting in quick read
and write operations.
Operating System 26
Capacity:
Main Memory: Main memory has a relatively limited capacity compared to
secondary memory. It is typically measured in gigabytes (GB) or terabytes
(TB), and its capacity affects the number of programs and data that can be
actively processed at any given time.
Cost:
Main Memory: Main memory is more expensive per unit of storage capacity
compared to secondary memory. The cost of main memory has decreased
over time but is still relatively higher due to its faster access speed and other
performance characteristics.
In summary, main memory is a fast, volatile, and limited-capacity storage used for
immediate data access by the CPU during program execution. Secondary
memory, on the other hand, is slower, non-volatile, and has a larger capacity,
serving as long-term storage for data that is not currently in use by the CPU.
Operating System 27
expression used to invoke the function. In other words, the decision of which
function to call is made during the compilation phase and remains unchanged
throughout program execution.
Static binding is typically used in languages with static typing, where the type of
variables is known at compile-time. Examples of languages that use static binding
include C, C++, and Java (for static methods).
The choice between static binding and dynamic binding depends on the
requirements of the programming language and the desired behaviour in different
situations. Static binding offers performance benefits and can be useful when the
function calls are known at compile-time, while dynamic binding provides
flexibility and runtime polymorphism capabilities.
Operating System 28
FCFS Scheduling
FCFS scheduling is a non-preemptive CPU scheduling algorithm in which the
process that arrives first is executed first. The CPU serves the processes in the
order they arrive in the ready queue. Once a process is allocated the CPU, it
continues to execute until it completes or voluntarily gives up the CPU.
3. No consideration for process burst time: FCFS does not take into account the
burst time or the amount of CPU time required by a process. It assumes that
all processes have the same priority and should be executed in the order they
arrive.
SJF Scheduling
SJF scheduling is a non-preemptive or preemptive CPU scheduling algorithm in
which the process with the shortest burst time is executed first. It aims to
minimise the average waiting time by selecting the shortest job from the ready
queue for execution.
Operating System 29
variant, if a new process with a shorter burst time arrives while a process is
already executing, the executing process may be preempted to allow the
shorter job to run.
SJF scheduling can achieve optimal average waiting time when the burst times of
processes are known in advance. However, predicting burst times accurately can
be challenging in practice. Variants of SJF, such as Shortest Remaining Time First
(SRTF), address this challenge by considering the remaining burst time of
processes.
SRTF Scheduling
SRTF scheduling is a preemptive CPU scheduling algorithm where the process
with the smallest remaining burst time is given the highest priority. It is based on
the concept of selecting the shortest job to execute next.
3. Efficient utilisation: SRTF aims to minimise the total time required to complete
all processes by giving preference to processes with shorter remaining burst
times.
Operating System 30
SRTF scheduling can achieve optimal average waiting time and response time
when the burst times of processes are known in advance. However, predicting
burst times accurately can be difficult in practice, which can lead to frequent
preemptions and overhead due to context switching.
LRTF Scheduling
This is a preemptive version of the Longest Job First (LJF) scheduling algorithm.
In this scheduling algorithm, we find the process with the maximum remaining
time and then process it. We check for the maximum remaining time after some
interval of time(say 1 unit each) to check if another process having more Burst
Time arrived up to that time.
Operating System 31
6. Throughput Considerations: LRTF does not specifically optimize for overall
system throughput. It focuses more on individual process performance and
minimizing waiting and response times.
Priority Scheduling
Priority Scheduling is a CPU scheduling algorithm where each process is assigned
a priority value, and the process with the highest priority is selected for execution.
If multiple processes have the same priority, other scheduling algorithms like
First-Come, First-Served (FCFS) or Round Robin (RR) can be used to decide the
order of execution among them.
Operating System 32
Round Robin (RR) scheduling is a CPU scheduling algorithm that allocates a fixed
time quantum or time slice to each process in the system, allowing them to
execute in a circular, cyclic manner.
3. Fairness: Round Robin scheduling aims to provide fair CPU allocation to all
processes. Since each process receives an equal time slice, no single process
can monopolize the CPU for an extended period.
Round Robin scheduling ensures that all processes receive CPU time fairly,
providing responsiveness and preventing starvation. However, it may introduce
performance issues when long-running processes or processes with higher
priorities dominate the CPU, causing other processes to experience increased
waiting times.
Operating System 33
The Producer-Consumer problem is a classic synchronization problem in
concurrent programming. It involves two types of processes, namely producers
and consumers, that share a common buffer or queue. The goal is to ensure that
producers can produce data items and add them to the buffer, while consumers
can consume the items from the buffer without conflicts or data corruption.
In short, here's how the Producer-Consumer problem is typically addressed:
2. Producers: Producers are responsible for generating data items and adding
them to the buffer. They may produce items at their own pace or in response
to certain events.
3. Consumers: Consumers retrieve and consume the items from the buffer. Like
producers, consumers can consume items at their own pace or in response to
specific triggers.
Operating System 34
consumption of items from a shared buffer.
Banker’s Algorithm
The Banker's algorithm is a resource allocation and deadlock avoidance algorithm
used in operating systems. It is designed to manage the allocation of resources to
processes in a way that avoids deadlocks and ensures the safety and progress of
the system. Here's a brief overview of the Banker's algorithm:
1. Resource Types: The system has a fixed number of resource types, such as
printers, memory blocks, or I/O devices. Each resource type has a certain
number of instances available.
The Banker's algorithm provides a method for the system to make informed
decisions about resource allocation, considering both current resource availability
and future resource requests. By ensuring the safety of the system and avoiding
Operating System 35
potential deadlocks, it contributes to the overall stability and reliability of the
operating system.
It's important to note that the Banker's algorithm assumes that processes declare
their maximum resource requirements in advance and do not exceed those limits.
It is commonly used in scenarios where resource allocation is critical, such as in
operating systems or distributed systems.
Explain Cache
A cache is a hardware or software component that stores frequently accessed
data or instructions in a smaller and faster memory, closer to the CPU, to improve
overall system performance. The main purpose of a cache is to reduce the time
and resources required to access data from the main memory, which is slower and
larger in capacity.
Caches work based on the principle of locality, which states that programs tend to
access data and instructions that are spatially or temporally close to each other.
Caches operate on the principle of the cache hierarchy, where smaller and faster
caches are closer to the CPU, while larger and slower caches are located further
away. When the CPU needs to access data or instructions, it first checks the
smallest and fastest cache (e.g., L1 cache). If the data is found in the cache
(cache hit), it is retrieved quickly. If the data is not present (cache miss), the CPU
checks the next level of cache or accesses the main memory directly.
Operating System 36
Caches use various algorithms, such as Least Recently Used (LRU) or Random
Replacement, to determine which data to keep in the cache and which data to
evict when space is limited. The goal is to maximize cache hits and minimize
cache misses to improve overall system performance.
Direct Mapping:
1. Mapping Technique: In direct mapping, each block of main memory is
mapped to a specific block in the cache memory using a direct mapping
function or formula.
2. One-to-One Mapping: Each block of main memory has only one specific
location in the cache where it can be placed.
3. Address Decomposition: The memory address is divided into three parts: the
tag, the index, and the block offset. The index bits determine the cache block
location for a given memory address.
4. Cache Conflicts: Direct mapping can lead to cache conflicts when multiple
memory addresses map to the same cache block due to limited cache
capacity.
6. Low Cache Utilisation: Direct mapping may result in lower cache utilisation
compared to other mapping techniques due to cache conflicts.
Associative Mapping:
Operating System 37
1. Mapping Technique: In associative mapping, a memory block can be placed
in any available cache block, without any restrictions or predetermined
location.
3. Address Comparison: The memory address is compared with the tags of all
cache blocks in parallel to determine if a cache hit occurs.
In summary, direct mapping maps each memory block to a specific cache block,
using a one-to-one mapping, while associative mapping allows any memory block
to be placed in any available cache block using a many-to-one mapping. Direct
mapping is simpler but can lead to cache conflicts, whereas associative mapping
eliminates cache conflicts but requires additional hardware complexity.
Operating System 38
3. Time Division: The CPU switches rapidly between different tasks, giving the
illusion of simultaneous execution. It allocates small time slices to each task,
allowing them to make progress.
Multiprocessing:
1. Definition: Multiprocessing involves the execution of multiple tasks
(processes or threads) on multiple CPUs (or CPU cores) simultaneously.
6. Resource Isolation: Each CPU or CPU core in multiprocessing has its own
resources, including cache, registers, and execution pipeline, enabling better
resource isolation and reducing contention.
Operating System 39