Operating System 1st Sem
Operating System 1st Sem
An Operating System (OS) is software that manages the hardware and software
resources of a computer and provides an environment for applications to run. Acting as
an intermediary between the user and the computer hardware, the OS performs
essential tasks like managing files, memory, processes, and devices to ensure that the
system operates efficiently and securely.
The interaction between an Operating System (OS) and the various components it
manages is fundamental to ensuring the computer functions smoothly. Here’s how the
OS interacts with different parts of the system and with users:
• The OS directly interacts with hardware through device drivers, which act as
translators between the OS and hardware components.
• It controls and manages resources like CPU, memory, storage devices,
input/output (I/O) devices (keyboard, mouse, printers), and network interfaces.
• The OS manages hardware access for processes, ensuring that multiple
programs can use the hardware safely and efficiently without conflict (e.g.,
sharing CPU time through scheduling algorithms).
• The OS organizes and manages data storage on drives using file systems,
enabling easy data retrieval and storage.
• It provides file management utilities for creating, deleting, copying, and
organizing files, with a hierarchical directory structure for easy access.
• The OS ensures security and access control for files, limiting access to
authorized users and programs.
Summary of OS Interaction
Operating systems come in various types, each designed to serve specific purposes
and environments. Here are the main types of operating systems:
• Definition: RTOS processes data and executes tasks within strict timing
constraints, ideal for systems that require immediate response.
• How it works: It ensures predictable response times, often through prioritized
scheduling, to meet real-time demands.
• Types:
o Hard RTOS: Missing a deadline can lead to system failure (e.g., industrial
robots).
o Soft RTOS: Some flexibility with deadlines, where delays aren’t critical
(e.g., streaming media).
• Example: VxWorks, QNX, and FreeRTOS.
• Uses: Used in mission-critical applications like medical devices, automotive
systems, and aerospace control.
Summary of Types
These types vary based on the computing environment, user requirements, and system
capabilities, each designed to address specific operational needs.
Time-Sharing Systems
Time-Sharing Systems are a type of operating system designed to allow multiple users
to interact with a computer simultaneously by sharing system resources, especially
CPU time. These systems create the illusion that each user has their own dedicated
system, even though they are actually sharing the computer’s resources with others.
• Efficient Resource Utilization: CPU, memory, and I/O resources are used
efficiently by switching between users and processes.
• Reduced Idle Time: The OS maximizes CPU usage by keeping it busy even when
some processes are waiting, such as for I/O operations.
• User Productivity: Multiple users can work on the system interactively,
improving productivity in environments like academic institutions and business
offices.
• Quick Response Time: Immediate feedback enables real-time interactions,
making it suitable for applications where instant response is necessary.
• UNIX: One of the earliest and most widely used time-sharing systems, popular in
academic, scientific, and enterprise environments.
• MULTICS: A pioneering time-sharing system that influenced modern OS
development, including UNIX.
• Windows Server: Allows multiple users to connect remotely and interact with a
shared server.
Summary
Time-sharing systems are ideal for environments where multiple users need interactive
access to shared resources, such as in universities, business offices, and online
platforms. By dividing CPU time and using multitasking, time-sharing OSs deliver a
responsive user experience while maximizing resource utilization.
Personal Computer Systems (PCs) are standalone computers designed for individual
use, providing a user-friendly interface and dedicated resources for personal
productivity, entertainment, and communication. Unlike multi-user systems such as
time-sharing computers, PCs are optimized for single-user applications, allowing a
single individual to interact with the system without sharing resources with others.
1. Single-User Focus:
a. PCs are typically designed for a single user at a time, making them ideal
for personal tasks, office work, or home use.
b. The operating system allocates system resources such as CPU, memory,
and storage exclusively to one user, allowing for more personalized
configurations and settings.
2. User-Friendly Operating Systems:
a. Personal computers commonly run desktop operating systems like
Microsoft Windows, macOS, and various Linux distributions.
b. These OSs feature intuitive graphical user interfaces (GUIs) with icons,
menus, and windows, allowing users to navigate easily without requiring
extensive technical knowledge.
3. Resource Availability:
a. In a PC, resources like processing power, memory, and storage are
dedicated to the user, providing faster, uninterrupted access.
b. While multitasking is supported, allowing users to run multiple
applications at once, PCs prioritize smooth operation for a single user
rather than balancing resources across multiple users.
4. Cost-Effective Hardware:
a. PCs are affordable and offer various hardware options to meet different
user needs, from basic desktops to high-performance gaming or
workstation PCs.
b. Typical hardware includes a CPU, RAM, storage (HDD or SSD), display,
and input devices like a keyboard and mouse, which can be customized
based on the user’s requirements.
5. Application Support:
a. Personal computers support a wide range of applications, including word
processing, web browsing, multimedia, gaming, and productivity tools.
b. They are compatible with software designed for general use, providing
flexibility for both work and leisure.
6. Network Connectivity:
a. PCs support connectivity options like Wi-Fi, Ethernet, and Bluetooth,
allowing them to connect to the internet and other devices.
b. While primarily used for individual work, PCs can also connect to local
networks, enabling file sharing and resource access within a home or
office network.
Types of Personal Computer Systems
• Ease of Use: PCs are designed for accessibility, offering GUIs and intuitive
features that make them user-friendly.
• Customizability: Users can configure PCs with specific hardware and software
to suit their personal needs and preferences.
• Performance: Personal computers dedicate resources to a single user,
enhancing performance and responsiveness.
• Cost-Effectiveness: PCs are affordable compared to multi-user systems,
making them accessible for individual users.
Summary
Parallel Systems
Parallel Systems are computer systems that use multiple processors (CPUs) to
execute multiple tasks simultaneously, improving computing speed, performance, and
efficiency. These systems aim to divide complex tasks across multiple processing
units, enabling faster execution and enhanced computational power, which is
especially useful in high-performance applications like scientific simulations, large-
scale data processing, and real-time applications.
1. Multiple Processors:
a. Parallel systems use more than one processor, with each CPU executing
a different part of the task simultaneously.
b. Processors may share memory (in shared-memory systems) or have
their own local memory (in distributed-memory systems).
2. Task Division and Distribution:
a. The primary task is split into smaller subtasks that can be processed
independently and concurrently.
b. The operating system or specific parallel processing software manages
the division and distribution of tasks among the processors.
3. Types of Parallel Systems:
a. Symmetric Multiprocessing (SMP): Multiple processors share a single
memory space and are controlled by a single OS, allowing them to access
shared data.
b. Massively Parallel Processing (MPP): Consists of many processors with
their own memory, connected by a high-speed network, often used in
supercomputers.
c. Cluster Computing: Multiple standalone computers (nodes) work
together as a cohesive system, communicating over a network to
complete tasks in parallel.
4. Synchronization and Coordination:
a. Tasks within parallel systems need to be synchronized and coordinated
to ensure data consistency and prevent conflicts.
b. Synchronization techniques, such as semaphores and locks, are used to
control access to shared resources.
5. Scalability:
a. Parallel systems are designed to be scalable, allowing additional
processors to be added to enhance performance.
b. This makes parallel systems highly suitable for applications that require
large-scale data processing, like machine learning and big data analytics.
Summary
Distributed Systems
• Resource Sharing: Users can access shared resources like storage, processing
power, and data, which are distributed across multiple nodes.
• High Availability and Reliability: Distributed systems can withstand individual
node failures, ensuring continuous availability.
• Scalability: Nodes can be added to handle increased demand, making
distributed systems highly scalable.
• Geographic Distribution: Data and processing can be distributed across
multiple locations, reducing latency and improving performance for global
users.
1. Client-Server Systems:
a. Clients request resources or services from central servers, which handle
processing and data storage.
b. Commonly used in web applications, where users interact with
applications hosted on remote servers.
2. Peer-to-Peer (P2P) Systems:
a. In P2P systems, each node acts as both a client and a server, sharing
resources directly with other nodes.
b. Examples include file-sharing networks and blockchain systems, where
nodes communicate and share data without centralized control.
3. Distributed Databases:
a. Databases spread across multiple servers or locations, allowing for data
redundancy and faster access times.
b. Popular examples include NoSQL databases like Cassandra, MongoDB,
and distributed SQL databases.
4. Cloud Computing Systems:
a. Cloud platforms like AWS, Google Cloud, and Microsoft Azure distribute
resources across data centers worldwide, providing on-demand storage,
computing, and services.
Examples of Distributed Systems
• Big Data Analytics: Distributed systems like Hadoop and Spark process and
analyze massive datasets by distributing computations across multiple nodes.
• Social Media: Platforms like Facebook, Twitter, and Instagram use distributed
systems to store, retrieve, and deliver content to millions of users.
• E-commerce: Online retail sites such as Amazon use distributed systems for
order processing, inventory management, and user recommendations.
Summary
1. Time-Constraint Requirements:
a. Real-time systems must complete tasks within specific timeframes to
function correctly, often requiring guaranteed response times.
b. Response time requirements can vary from milliseconds to seconds,
depending on the application.
2. Predictability and Determinism:
a. Real-time systems focus on predictability, ensuring that tasks are
completed in a reliable and repeatable manner.
b. Deterministic behavior is essential, meaning that the system’s response
is predictable and occurs within the specified time limit.
3. Classification by Deadline Types:
a. Hard Real-Time Systems: Must meet their deadlines without fail.
Missing a deadline can lead to severe consequences, as seen in systems
for medical monitoring, aircraft control, or nuclear power control.
b. Soft Real-Time Systems: Aim to meet deadlines most of the time, with
some tolerance for occasional delays. Examples include video streaming,
where minor delays are noticeable but not critical.
c. Firm Real-Time Systems: Missing a deadline does not cause a
catastrophic event but renders the specific task’s results useless. An
example is in quality control systems, where data is only useful within
specific time windows.
4. Concurrent Task Management:
a. Real-time systems often need to handle multiple tasks simultaneously,
with tasks prioritized based on urgency.
b. Real-time operating systems (RTOS) provide scheduling mechanisms like
priority-based scheduling to ensure critical tasks are completed on time.
5. Resource Constraints:
a. Real-time systems may operate with limited memory, processing power,
or battery life, especially in embedded systems.
b. Efficient resource management is vital to meet timing requirements while
maintaining system reliability.
• Timely Responses: Ensure tasks are completed within a specified time frame,
critical for applications where delays can lead to severe outcomes.
• High Reliability: Designed to operate continuously and handle faults with
minimal disruption, ideal for safety-critical environments.
• Predictable Behavior: Real-time systems provide consistent, predictable
responses, making them suitable for applications requiring strict timing.
Summary
Real-time systems are designed to perform tasks within strict timing constraints,
ensuring predictability, reliability, and responsiveness. Used across critical
applications in healthcare, automotive, industrial automation, and
telecommunications, these systems require careful design and specialized operating
systems (RTOS) to meet timing and concurrency demands while operating efficiently
within resource constraints.
System Components
System Components refer to the various hardware and software elements that work
together to create a functional computing system. Understanding these components is
essential for grasping how systems operate and interact with each other.
Hardware Components
1. Program Execution
• Loading and Execution: The OS loads programs into memory and manages their
execution.
• Process Management: Manages processes (running programs), including
scheduling, creation, and termination of processes.
2. I/O Operations
• File Management: The OS provides services to create, delete, read, write, and
manipulate files and directories.
• Directory Management: Organizes files in a hierarchical structure, facilitating
easy access and retrieval.
4. Communication Services
6. Resource Allocation
8. User Interface
9. Accounting
• Batch Processing: The OS manages batch jobs and queues, allowing multiple
jobs to be processed in sequence without user intervention.
• Time-sharing: Implements time-sharing techniques to allow multiple users to
interact with the system simultaneously, sharing CPU time and resources.
System Calls
System Calls are essential interfaces between user applications and the operating
system (OS). They provide the means for programs to request services from the OS,
allowing applications to perform operations such as file manipulation, process control,
and communication. Understanding system calls is crucial for both software
development and operating system design.
1. Process Control:
a. Used to manage processes and their execution.
b. Examples:
i. fork(): Creates a new process.
ii. exec(): Replaces the current process image with a new one.
iii. wait(): Waits for a process to change state (e.g., termination).
iv. exit(): Terminates a process.
2. File Manipulation:
a. Allow programs to perform operations on files.
b. Examples:
i. open(): Opens a file.
ii. read(): Reads data from a file.
iii. write(): Writes data to a file.
iv. close(): Closes an opened file.
v. unlink(): Deletes a file.
3. Device Management:
a. Enable communication with hardware devices.
b. Examples:
i. ioctl(): Configures device parameters.
ii. read(), write(): Interact with device files.
4. Information Maintenance:
a. Provide information about the system and processes.
b. Examples:
i. getpid(): Returns the process ID of the calling process.
ii. getppid(): Returns the parent process ID.
iii. sysinfo(): Retrieves system information.
5. Communication:
a. Facilitate communication between processes.
b. Examples:
i. pipe(): Creates a pipe for inter-process communication.
ii. shmget(): Allocates a shared memory segment.
iii. msgsnd(): Sends a message to a message queue.
1. Library Wrappers:
a. Most programming languages provide library functions that act as
wrappers for system calls. For example, in C, functions like fopen() and
fread() wrap the underlying system calls.
2. Transition to Kernel Mode:
a. When a system call is invoked, the CPU switches from user mode (where
applications run) to kernel mode (where the OS executes), allowing the
OS to perform the requested service.
3. Context Switching:
a. The OS saves the current state of the process and switches to the kernel's
context to handle the system call. After completion, it switches back to
the user context, restoring the process's state.
4. Error Handling:
a. System calls return status codes to indicate success or failure. In case of
failure, they may set a global variable (e.g., errno in C) to provide details
about the error.
• In Unix/Linux:
o Process Control: fork(), exec(), wait(), exit()
o File Manipulation: open(), read(), write(), close()
o Communication: pipe(), msgsnd(), recv()
• In Windows:
o Process Control: CreateProcess(), TerminateProcess(),
WaitForSingleObject()
o File Manipulation: CreateFile(), ReadFile(), WriteFile(),
CloseHandle()
o Communication: CreateEvent(), WaitForMultipleObjects()
System Programs
System Programs are essential software components that provide a variety of services
and functionalities to manage the hardware and software resources of a computer
system. They act as an intermediary between the user applications and the operating
system, facilitating the operation of the system and enhancing the user experience.
Here’s a detailed overview of system programs:
1. Resource Management:
a. System programs manage and allocate system resources, including
memory, CPU time, and storage, ensuring efficient operation and optimal
performance.
2. User Interaction:
a. They provide interfaces for users to interact with the operating system
and applications, enabling file management, process control, and system
configuration.
3. System Monitoring:
a. System programs monitor system performance, resource usage, and
process execution, providing insights and statistics that help maintain
system health.
4. Error Handling:
a. They assist in diagnosing and correcting errors in both hardware and
software components, enhancing system stability and reliability.
5. System Configuration:
a. System programs allow users to configure system settings and
preferences, tailoring the system to individual needs and improving
usability.
• Windows:
o File Explorer
o Task Manager
o Command Prompt
o Windows Defender (antivirus)
o Disk Cleanup Utility
• Linux:
o ls, cp, mv, rm (file management commands)
o top, htop (process monitoring)
o gcc (GNU Compiler Collection)
o ssh (Secure Shell for remote access)
o iptables (firewall management)
Process Control
What is a Process?
A process is an instance of a program that is being executed. It is more than just the
program code; it includes the following components:
1. Program Code (Text Segment): The actual instructions that make up the
program.
2. Program Counter (PC): A pointer that indicates the next instruction to be
executed.
3. Process Stack: Contains temporary data such as method parameters, return
addresses, and local variables.
4. Data Section: Contains global variables used by the process.
5. Heap: Dynamically allocated memory during the process’s runtime.
Process States
Processes can be in various states during their lifecycle. The main process states
include:
The Process Control Block (PCB) is a data structure maintained by the operating
system for each process. It contains important information about the process,
including:
Process Lifecycle
1. Creation: The operating system creates a new process, initializing its PCB and
allocating necessary resources.
2. Execution: The process enters the running state when it is allocated CPU time.
3. Waiting: If the process requires I/O or needs to wait for some event, it enters the
waiting state.
4. Termination: After completing its task or being terminated, the process is
removed from memory, and its PCB is deleted.
Process Scheduling
Process Scheduling is the method by which the operating system decides the order in
which processes are executed. The main goals of scheduling are to maximize CPU
utilization, ensure fairness among processes, minimize waiting time, and achieve high
throughput.
Types of Scheduling
1. Long-term Scheduling:
a. Determines which processes are admitted to the system for processing.
b. Controls the degree of multiprogramming (number of processes in
memory).
2. Short-term Scheduling (CPU Scheduling):
a. Selects which process from the ready queue will be executed next by the
CPU.
b. Involves frequent context switches, typically managed by a scheduler.
3. Medium-term Scheduling:
a. Involves swapping processes in and out of memory to manage the degree
of multiprogramming.
b. Helps balance the load and optimize performance.
Scheduling Algorithms
Various algorithms are used for CPU scheduling, each with its own advantages and
disadvantages. Common scheduling algorithms include:
Process Scheduling
Types of Scheduling
Scheduling Algorithms
Various algorithms determine how processes are scheduled, each with its own benefits
and drawbacks. Here are some common scheduling algorithms:
Scheduling Metrics
Operations on Process
Process creation involves initializing a new process and allocating the necessary
resources for it. This operation can occur in several ways:
• System Calls: The OS provides system calls like fork() in Unix/Linux that
create a new process. The newly created process is a duplicate of the parent
process.
• Process Control Block (PCB): A new PCB is created for the new process,
containing all the relevant information (process ID, state, program counter, etc.).
2. Process Termination
3. Process Scheduling
Process scheduling involves selecting processes from the ready queue to be executed
by the CPU. This operation is handled by the short-term scheduler (dispatcher).
Steps in Process Scheduling:
Process suspension involves temporarily halting a process's execution and saving its
state, allowing other processes to execute. This is often done to manage resources
more effectively.
5. Process Communication
The operating system continuously monitors and manages the state of processes as
they transition between different states (New, Ready, Running, Waiting, Terminated).
Key Operations:
Cooperating Processes
Threads
Threads are the smallest unit of processing that can be scheduled by an operating
system. They represent a lightweight alternative to traditional processes, allowing for
efficient execution of concurrent tasks within a program. Here’s a detailed overview of
threads, their characteristics, benefits, types, and challenges.
Characteristics of Threads
Types of Threads
1. User Threads: These are threads that are created and managed by user-level
libraries or applications rather than the operating system. User threads provide a
higher-level abstraction and are generally more portable across different
operating systems.
2. Kernel Threads: These threads are managed by the operating system kernel.
Each kernel thread has its own PCB (Process Control Block) and can be
scheduled independently. This allows the operating system to take advantage of
multi-core architectures more effectively.
3. Hybrid Threads: This approach combines user threads and kernel threads,
where user-level libraries manage the user threads while the kernel manages the
kernel threads. This allows for greater flexibility and efficiency.
Thread Management
Thread management involves various operations that the operating system provides for
creating, controlling, and terminating threads. Key functions include:
CPU Scheduling
Various algorithms are used to schedule processes in the CPU. Each algorithm has its
own advantages and disadvantages, depending on the workload and system goals.
Some common CPU scheduling algorithms include:
2. Process States
3. Context Switching
Context switching is the process of saving the state of a currently running process so
that it can be resumed later, and loading the state of the next process to be executed.
This involves:
While context switching allows for multitasking, it introduces overhead due to the time
required to save and load process states.
4. Scheduling Metrics
• Waiting Time: The total time a process has been in the ready queue.
• Response Time: The time from submission of a request until the first response
is produced (important in interactive systems).
• Throughput: The number of processes completed in a given time frame.
• CPU Utilization: The percentage of time the CPU is actively executing
processes.
Scheduling Criteria
Scheduling criteria are the metrics and standards used to evaluate the effectiveness
of CPU scheduling algorithms. These criteria help determine how well a scheduling
algorithm performs in terms of efficiency, responsiveness, and resource utilization.
Here are the key scheduling criteria:
1. CPU Utilization
• Definition: The number of processes that complete their execution per unit time
(e.g., processes per second).
• Goal: Maximize throughput to ensure that more processes are completed in a
given time frame.
• Importance: Higher throughput results in better system performance and user
satisfaction, especially for batch processing systems.
3. Turnaround Time
• Definition: The total time taken from the submission of a process to its
completion.
4. Waiting Time
• Definition: The total time a process spends in the ready queue waiting for CPU
time.
5. Response Time
• Definition: The time from the submission of a request until the first response is
produced.
• Goal: Minimize response time to ensure that users receive feedback quickly.
• Importance: Response time is particularly crucial in interactive and real-time
systems, enhancing user satisfaction.
6. Fairness
• Definition: Ensuring that all processes get a fair share of CPU time, preventing
starvation of low-priority processes.
• Goal: Achieve fairness in CPU allocation to promote equality among processes.
• Importance: Fairness is essential in multi-user systems and ensures that all
users and processes are treated equitably.
7. Starvation
• Definition: The time taken to save the state of the currently running process and
load the state of the next process to be executed.
• Goal: Minimize context switch time to reduce overhead.
• Importance: Frequent context switching can degrade performance, so efficient
management of context switches is essential for optimal scheduling.
Scheduling Algorithms
• Description: Processes are scheduled in the order they arrive in the ready
queue. The first process to arrive is the first to be executed.
• Characteristics:
o Non-preemptive.
o Simple to implement.
• Advantages:
o Easy to understand and implement.
o Fair in terms of process ordering.
• Disadvantages:
o Can lead to the convoy effect, where short processes wait for long
processes to finish.
o High average waiting time, especially with a mix of short and long
processes.
• Description: The process with the smallest execution time (burst time) is
scheduled next.
• Characteristics:
o Can be preemptive or non-preemptive.
• Advantages:
o Minimizes average waiting time and turnaround time.
• Disadvantages:
o Requires knowledge of the burst time in advance, which is often not
feasible.
o Can lead to starvation for longer processes if shorter ones keep arriving.
• Description: Each process is assigned a priority, and the CPU is allocated to the
highest priority process.
• Characteristics:
o Can be preemptive or non-preemptive.
• Advantages:
o Can be efficient for certain workloads that favor priority processing.
• Disadvantages:
o Can lead to starvation for low-priority processes.
o Complexity in managing and assigning priorities.
• Description: Processes are divided into multiple queues based on their priority
or type (e.g., foreground vs. background). Each queue can have its own
scheduling algorithm.
• Characteristics:
o Can include both preemptive and non-preemptive algorithms.
• Advantages:
o Flexible and allows for different scheduling strategies for different types
of processes.
• Disadvantages:
o Complexity in managing multiple queues and scheduling policies.
o Potential for starvation in lower-priority queues.
Concurrency
1. Mutual Exclusion
2. Critical Section
3. Synchronization
4. Deadlock
6. Non-blocking Synchronization
7. Memory Consistency
3. Load-Link/Store-Conditional (LL/SC)
5. Memory Barriers
• Definition: Memory barriers (or memory fences) are hardware instructions that
ensure memory operations are completed in a specific order.
• Purpose: They prevent the CPU and compiler from reordering memory
operations, ensuring that changes made by one thread are visible to others in
the intended order.
• Usage: Memory barriers are often used in conjunction with atomic operations to
ensure the correctness of concurrent algorithms.
6. Interrupt Disabling
Semaphores
Basic Operations
Advantages:
Disadvantages:
Message Passing
1. Processes: Independent entities that can run concurrently. Each process has its
own memory space and can communicate with other processes through
messages.
2. Messages: Units of data sent from one process to another. Messages can
contain various types of information, such as commands, data, or notifications.
3. Communication: This can be either:
a. Synchronous: The sender waits until the receiver acknowledges receipt
of the message. This ensures that the message is received before
continuing.
b. Asynchronous: The sender sends the message and continues without
waiting for the receiver to acknowledge receipt. This allows for non-
blocking communication.
1. Direct Communication:
a. The sender and receiver must know each other’s identities. The sender
specifies the receiver’s process ID when sending a message.
b. Example: A process sends a message directly to another specific
process.
2. Indirect Communication:
a. Messages are sent to a shared mailbox or queue, from which the receiver
can retrieve them.
b. Example: A process sends a message to a common mailbox, and any
process can read from it.
1. Send: A process sends a message to another process. This operation may block
if the communication is synchronous.
2. Receive: A process receives a message sent to it. This operation may also block
until a message is available.
• Overhead: Sending and receiving messages can introduce latency and require
more resources compared to shared memory communication.
• Complexity: Managing message formats and ensuring that messages are sent
and received correctly can add complexity to the system.
• Synchronization: Care must be taken to synchronize message sending and
receiving, especially in asynchronous communication.
Key Points
1. Requirements:
a. Multiple readers can read at the same time.
b. Writers must have exclusive access—no readers or other writers should
access the resource during writing.
c. Fairness must be maintained to prevent starvation of either readers or
writers.
2. Types:
a. First Readers/Writers Problem: Prioritizes readers; writers wait if any
readers are present.
b. Second Readers/Writers Problem: Prioritizes writers; readers wait if a
writer is present.
1. Semaphores:
a. mutex: Protects the count of active readers.
b. wrt: Ensures exclusive access for writers.
2. Reader Process:
a. Acquires mutex to update the reader count.
b. If it's the first reader, locks wrt to prevent writers.
c. After reading, it updates the count and releases wrt if it’s the last reader.
3. Writer Process:
a. Acquires wrt for exclusive access.
b. Writes to the resource and then releases wrt.
Deadlock Detection
Deadlock Recovery
1. Process Termination:
a. Kill Processes: Abort one or more processes involved in the deadlock to
break the cycle.
i. Choosing Which Process to Kill:
1. Based on priority (kill lower-priority processes).
2. Based on resource usage (kill processes holding more
resources).
3. Based on the process’s age (kill the younger process).
b. Rollback: If the system supports it, processes can be rolled back to a
safe state prior to the deadlock.
2. Resource Preemption:
a. Temporarily take resources away from one or more processes to break
the deadlock.
i. Forcefully Retrieving Resources: Involves reclaiming resources
from a process and potentially rolling it back to ensure
consistency.
b. This approach requires careful management to avoid inconsistent states.
3. Wait-Die and Wound-Wait Schemes:
a. Wait-Die Scheme:
i. Older processes can wait for resources held by younger
processes.
ii. Younger processes requesting resources held by older processes
are aborted (killed).
b. Wound-Wait Scheme:
i. Older processes that request resources held by younger
processes are aborted (wounded).
ii. Younger processes can wait for resources held by older
processes.
Deadlock Avoidance
Key Concepts
1. Resource Allocation:
a. In deadlock avoidance, resources are allocated to processes only if it is
safe to do so. A safe state is defined as a state where at least one
sequence of process execution will lead to the completion of all
processes without causing a deadlock.
2. Safe and Unsafe States:
a. Safe State: A state where there exists a sequence of processes such that
each process can obtain its maximum required resources without leading
to a deadlock.
b. Unsafe State: A state that can lead to deadlock if resources are allocated
based on the current requests of processes.
3. Banker’s Algorithm:
a. One of the most well-known algorithms for deadlock avoidance,
developed by Edsger Dijkstra. It simulates resource allocation for
processes to ensure that the system remains in a safe state.
b. Working:
i. Each process must declare its maximum resource needs in
advance.
ii. The algorithm checks whether granting a resource request would
leave the system in a safe state.
iii. If it would, the request is granted; if not, the process must wait.
Deadlock Prevention
Deadlock prevention is a strategy used to ensure that a system never enters a deadlock
state by actively negating one or more of the conditions required for deadlocks to
occur. It aims to prevent deadlocks by controlling how processes acquire resources
and how they interact with each other. Here are the key concepts and strategies
associated with deadlock prevention:
Four Necessary Conditions for Deadlocks
Deadlocks occur when all four of the following conditions hold simultaneously:
When discussing deadlocks in operating systems, several other issues are connected
to or arise from deadlocks. These issues can affect system performance, resource
management, and overall efficiency. Here are some key topics related to deadlocks:
• 1. Starvation
2. Livelock
5. Performance Overhead
8. Transaction Management
File access methods define how data can be read from or written to a file. Common
access methods include:
1. Sequential Access:
a. Data is accessed in a linear order, one record after another.
b. Suitable for applications that process data in a specific sequence (e.g.,
text files).
2. Direct Access (Random Access):
a. Data can be read or written in any order, allowing random access to any
part of the file.
b. Ideal for applications requiring quick retrieval of specific records (e.g.,
databases).
3. Indexed Access:
a. An index is maintained for the file, which maps keys to their respective
data locations.
b. Enhances search efficiency, allowing quick access to records based on
keys.
Directory Structure
• Definition: The file system is responsible for managing how files are stored,
accessed, and organized on storage devices.
• Components:
o File Control Block (FCB): Contains metadata about a file, including its
attributes, location, size, and access permissions.
o Inodes: In Unix-like systems, inodes store file metadata and point to the
data blocks on the disk.
o Data Blocks: The actual data of files is stored in blocks on the disk.
File allocation methods determine how files are stored on the disk. Common methods
include:
1. Contiguous Allocation:
a. Files are stored in contiguous blocks on the disk.
b. Benefits: Simple and provides fast access.
c. Drawbacks: Can lead to fragmentation and difficulty in allocating space
for growing files.
2. Linked Allocation:
a. Each file consists of a linked list of blocks scattered across the disk.
b. Benefits: No fragmentation and can grow easily.
c. Drawbacks: Slower access times due to pointer traversal.
3. Indexed Allocation:
a. Each file has an index block that contains pointers to its data blocks.
b. Benefits: Combines benefits of contiguous and linked allocation, allowing
for fast access and easy growth.
c. Drawbacks: Overhead of maintaining index blocks.
Free-Space Management
2. Secondary Memory
3. Cache Memory
4. Virtual Memory
• Definition: The logical address space (or virtual address space) is the set of
addresses that a program uses during its execution. These addresses are
generated by the CPU and are independent of the actual physical addresses in
memory.
• Characteristics:
o Process Isolation: Each process operates in its own logical address
space, which provides isolation and security.
o Abstraction: Logical addresses allow programmers to write code without
needing to worry about the actual memory layout.
o Address Translation: The operating system, through hardware support
(like the Memory Management Unit), translates logical addresses to
physical addresses when accessing memory.
• Definition: The physical address space refers to the actual locations in the
computer's RAM where data and instructions reside. These addresses
correspond to the real hardware memory.
• Characteristics:
o Hardware Dependent: Physical addresses depend on the computer’s
architecture and the actual physical memory available.
o Memory Management: The operating system is responsible for managing
physical memory and translating logical addresses to physical
addresses.
Swapping
Contiguous Allocation
Paging
Segmentation
Demand Paging
• Definition: Demand paging is a technique where pages are loaded into memory
only when they are needed, rather than loading the entire process into memory
at once.
• Characteristics:
o Lazy Loading: Pages are loaded into memory on-demand when a page
fault occurs (i.e., when a process tries to access a page that is not
currently in memory).
o Efficiency: This allows the system to use memory more efficiently, as
only the necessary pages are loaded, reducing the overall memory
footprint.
• Page Fault Rate: The performance of demand paging is heavily influenced by the
page fault rate, which is the frequency of page faults occurring during program
execution.
• Factors Affecting Performance:
o Locality of Reference: Programs tend to access a limited set of pages
repeatedly, which can improve performance if those pages are kept in
memory.
o Page Replacement Strategies: The efficiency of page replacement
algorithms can significantly affect the overall performance of demand
paging.
Page Replacement
Several algorithms can be used for page replacement, each with its advantages and
disadvantages: