0% found this document useful (0 votes)
19 views

Operating System

Uploaded by

Tech Proffesor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Operating System

Uploaded by

Tech Proffesor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

OPERATING SYSTEM

An operating system (OS) is a software that serves as an interface


between a computer user and computer hardware.
It performs essential tasks such as file management, memory
management, process management, input/output handling, and
controlling peripheral devices.
The core component of an operating system is called the kernel.
The primary purposes of an operating system are to enable
applications to interact with hardware and to manage a system's
hardware and software resources.
Operating systems can be found in various devices such as mobile
phones, personal computers, mainframe computers, automobiles,
TVs, and toys.
Popular operating systems include Linux, Windows, VMS, OS/400,
AIX, z/OS, and others.
An operating system supports a computer's basic functions, such as
task scheduling and peripheral control.
It acts as an intermediary between the user and the computer
hardware, controlling the execution of programs.
The operating system manages computer hardware and software
resources and provides common services for computer programs.
L
Functions of an Operating System:
Process Management:
Allocates system resources to different processes
Schedules the execution of processes
Manages inter-process communication and synchronization
Memory Management:
Tracks and allocates memory resources to processes
Handles virtual memory management through techniques like
paging and swapping
File System Management:
Organizes and manages the storage of data on secondary storage
devices
Handles file creation, deletion, and access
Manages directories and ensures data integrity and security
Device Management:
Manages computer hardware devices (input/output, storage, etc.)
Provides device drivers for communication between software and
hardware
User Interface:
Provides a command-line or graphical interface for user interaction
Allows execution of programs, file management, and system
configuration
Security and Protection:
Implements security measures to protect the system and user data
Controls user authentication and authorization
Enforces access control policies and provides data encryption
Networking:
Supports communication between computers and devices over
networks
Manages network connections, protocols, and configurations
OS AS AN resource manager
The operating system manages and distributes computer resources
like the CPU and memory to different programs and tasks.
It ensures that each program gets a fair share of resources,
preventing one program from using up all the computer's power.
The operating system decides which program should run when,
scheduling their execution to make the best use of available
resources.
It controls the use of memory, assigning and freeing up space for
programs as needed.
The operating system handles file storage, organizing and managing
data on the computer's disks.
It manages access to devices like printers and scanners, allowing
multiple programs to use them without conflicts.
The operating system handles interruptions from devices, making
sure they get attention and don't disrupt the system.
It allows programs to communicate and share information with each
other, helping them work together.
The operating system keeps an eye on the computer's performance,
making adjustments to optimize resource usage.
It protects resources from unauthorized access, making sure only
authorized users can use them and keeping data safe.
operating system acts as an extended machine,
The operating system acts as an extended machine, providing a user-
friendly interface that allows users to interact with the computer's
hardware and software.
It hides the complexities of hardware operations and presents a
simplified interface for users to perform tasks easily.
The operating system enables users to run applications and execute
commands without needing to understand the underlying hardware
details.
It provides a layer of abstraction between the user and the hardware,
allowing programs to run on different types of computers without
modifications.
The operating system manages hardware resources and translates
user commands into instructions that the hardware can understand
and execute.
It handles input and output operations, allowing users to interact
with devices such as keyboards, mice, and displays.
The operating system provides services and utilities that extend the
capabilities of the hardware, such as file management, networking,
and security features.
It acts as a bridge between users and the physical machine, enabling
users to utilize the full potential of the computer system in a user-
friendly manner.
HISTORY OF OS
Operating
Year Description
System
Early batch processing system developed by
1956 GM-NAA I/O
IBM.
SHARE
Designed for IBM mainframes, allowed
1959 Operating
resource sharing.
System
IBM's first mainframe OS, introduced virtual
1964 OS/360
memory.
Developed by AT&T Bell Labs, known for
1969 UNIX
its portability.
Popular microcomputer OS, influenced MS-
1971 CP/M
DOS.
Microsoft Disk Operating System for IBM-
1980 MS-DOS
compatible PCs.
1984 Macintosh Apple's GUI-based OS for Macintosh
System computers.
Operating
Year Description
System
Software
Microsoft's graphical OS, marked the
1985 Windows 1.0
Windows series.
Open-source OS developed by Linus
1991 Linux
Torvalds.
Major Windows release with significant UI
1995 Windows 95
improvements.
Long-lasting Windows version, stable and
2001 Windows XP
user-friendly.
Windows release with enhanced visuals and
2007 Windows Vista
security.
Apple's modern OS for Mac computers,
2007 macOS (OS X)
based on UNIX.
Linux-based mobile OS developed by
2008 Android
Google.
Introduced touch-centric interface for PCs
2012 Windows 8
and tablets.
Current major Windows release, combining
2014 Windows 10
new features.
macOS (macOS Apple's OS version with improved file
2017
High Sierra) system and graphics.
Windows 10 Latest stable release of Windows as of
2020
(20H2) knowledge cutoff.
Types of os
Batch Operating System:
Designed for executing a sequence of similar jobs without human
intervention.
Users submit jobs in batches, and the operating system executes
them one after another.
Each job is processed in isolation, without interaction with the user
or other jobs.
Batch OS optimizes resource utilization by minimizing idle time
between jobs.
Commonly used in scenarios where the input data is known in
advance, such as payroll processing or large-scale data processing.
Multiprogramming Operating System:
Allows multiple programs to reside in memory simultaneously.
Programs are selected and executed by the CPU based on scheduling
algorithms.
Improves CPU utilization by keeping the CPU busy with one
program while another program waits for I/O.
Enables efficient sharing of system resources like memory, CPU,
and devices among different programs.
Provides the illusion of concurrent execution, even though only one
program executes at a time on a single CPU.
Multitasking Operating System:
Enables concurrent execution of multiple tasks/programs.
Each task receives a small time slice called a time quantum or time
slice.
The operating system rapidly switches between tasks, giving the
appearance of simultaneous execution.
Allows users to run multiple applications simultaneously, enhancing
productivity and user experience.
Provides mechanisms to prioritize tasks, allocate resources, and
manage task synchronization and communication.
Time-Sharing Operating System:
Similar to multitasking OS, but with a stronger focus on providing
interactive computing.
Enables multiple users to simultaneously access the system through
terminals or remote connections.
Provides fair and efficient time division among users, giving each
user the perception of dedicated access.
Supports features like virtual memory, file sharing, and security
mechanisms to protect user data and system integrity.
Time-sharing OS typically includes a command-line interface or
graphical user interface (GUI) for user interaction.
Real-Time Operating System (RTOS):
Designed for applications that require precise and deterministic
timing responses.
Real-time tasks have deadlines, and the OS guarantees that these
deadlines are met.
Provides mechanisms for real-time task scheduling, prioritization,
and resource allocation.
Often used in embedded systems, robotics, aerospace, industrial
control systems, and other time-critical applications.
Offers predictable and low-latency response times, ensuring timely
completion of critical operations.
Introduction to System Call:
A system call is a programmatic interface provided by the operating
system that allows user-level processes to request services from the
kernel.
System calls provide an abstraction layer between user-level
applications and the low-level hardware and resources of the
computer system.
Common system calls include opening or creating files, reading or
writing data, allocating memory, creating processes, and managing
I/O operations.
System calls are typically invoked by executing specific software
interrupt instructions or by using library functions that wrap the
underlying system call.
System calls provide a secure and controlled way for user programs
to interact with the underlying operating system and access system
resources.
The Shell:
The shell is a command-line interface (CLI) or a scripting language
interpreter that allows users to interact with the operating system.
It provides a textual interface where users can enter commands and
receive corresponding outputs or perform specific operations.
The shell interprets user commands and executes them by invoking
the appropriate system calls or executing other programs.
Shell scripting enables users to write scripts consisting of multiple
commands and control structures for automation or complex tasks.
Common shells include Bash (Bourne Again SHell), PowerShell,
Zsh (Z Shell), and Csh (C Shell), each with its own syntax and
features.
Open Source Systems:
Open source refers to software that provides its source code openly,
allowing users to view, modify, and distribute the code.
Open source systems foster collaboration, transparency, and
community-driven development.
Developers can access and modify the source code to customize and
extend the software to meet their specific needs.
Open source systems often have vibrant communities that contribute
bug fixes, new features, and improvements to the software.
Examples of popular open source systems include the Linux
operating system, the Apache web server, the MySQL database
management system, and the Mozilla Firefox web browser.
Definition of Process:In the context of an operating system, a
process refers to a running instance of a program or application.It
represents the execution of a specific set of instructions, along with
the associated resources and data required to carry out those
instructions.A process is an independent entity with its own memory
space, program counter, stack, and other attributes, allowing it to
execute concurrently with other processes on a multi-tasking or
multi-programming operating system.
Program Process
Program contains a set of
Process is an instance of an executing
instructions designed to
program.
complete a specific task.
Program is a passive entity asProcess is a active entity as it is
it resides in the secondary created during execution and loaded
memory. into the main memory.
Program exists at a single Process exists for a limited span of
place and continues to exist time as it gets terminated after the
until it is deleted. completion of task.
Program is a static entity. Process is a dynamic entity.
Program does not have any Process has a high resource
resource requirement, it only requirement, it needs resources like
requires memory space for CPU, memory address, I/O during its
storing the instructions. lifetime.
Program does not have any Process has its own control block
control block. called Process Control Block.
In addition to program data, a process
Program has two logical also requires additional information
components: code and data. required for the management and
execution.
Many processes may execute a single
Program does not change program. There program code may be
itself. the same but program data may be
different. these are never same.
Program is a passive entity. Process is active entity.
Program contains Process is a sequence of instruction
instructions execution.
A program exists at single Process exists in a limited span of
place and continues to exist. time.
Program is a static entity. Process is a dynamic entity.
Process Model
A process model in an operating system provides a structured
representation of the different states and transitions a process goes
through during its lifecycle, from creation to termination.
It defines the set of states, such as new, ready, running, blocked, and
terminated, along with the rules and mechanisms for transitioning
between these states, allowing the operating system to manage and
control the execution of processes efficiently.

Five-State Process Model States:


New: Newly created process waiting for approval by the operating
system.
Ready: Process loaded into main memory and ready to run.
Running: Currently executing process on the CPU.
Blocked/Waiting: Processes that have left the CPU and are waiting
for an event or resource.
Exit/Terminated: Process that has completed execution and been
removed from the CPU and main memory.
State Transitions:
Null -> New: Creation of a new process.
New -> Ready: Transition from new to ready state, indicating
readiness for execution.
Ready -> Running: Selection of a process from the ready state for
execution.
Running -> Exit: Process completes execution or is aborted and
terminated.
Running -> Ready: Running process reaches its maximum
running time.
Running -> Blocked: Process enters the blocked state while waiting
for an event or resource.
Blocked -> Ready: Event for which the process was waiting occurs,
transitioning it back to the ready state.
Ready -> Exit: Occurs in specific circumstances when a parent
process terminates a child process.
Remember that the Five-State Process Model provides a more
comprehensive representation of process states and their transitions,
addressing limitations of the Two-State M
Advantages:
Introduction of New and Exit states improves process management.
More efficient compared to the Two-State Model.
Disadvantages:
The operating system does not save data when a process is
terminated or exited.
Processor idle time can occur when processes are in the blocked
state, potentially impacting performance.
process states and transitions
Process is an instance of a program in execution. A set of processes
combined together make a complete program. There are two
categories of processes in Unix, namely
User processes: They are operated in user mode.
Kernel processes: They are operated in kernel mode.
Process states
The states that a Process enters in working from start till end are
known as Process states. These are listed below as:
Created-Process is newly created by system call, is not ready to run
User running-Process is running in user mode which means it is a
user process.
Kernel Running-Indicates process is a kernel process running in
kernel mode.
Zombie- Process does not exist/ is terminated.
Preempted- When process runs from kernel to user mode, it is said
to be preempted.
Ready to run in memory- It indicated that process has reached a
state where it is ready to run in memory and is waiting for kernel to
schedule it.
Ready to run, swapped– Process is ready to run but no empty main
memory is present
Sleep, swapped- Process has been swapped to secondary storage
and is at a blocked state.
Asleep in memory- Process is in memory(not swapped to secondary
storage) but is in blocked state.
The numbers indicate the steps that are followed.
Process Transitions
The working of Process is explained in following steps:
User-running: Process is in user-running.
Kernel-running: Process is allocated to kernel and hence, is in
kernel mode.
Ready to run in memory: Further, after processing in main
memory process is rescheduled to the Kernel.i.e.The process is not
executing but is ready to run as soon as the kernel schedules it.
Asleep in memory: Process is sleeping but resides in main memory.
It is waiting for the task to begin.
Ready to run, swapped: Process is ready to run and be swapped by
the processor into main memory, thereby allowing kernel to schedule
it for execution.
Sleep, Swapped: Process is in sleep state in secondary memory,
making space for execution of other processes in main memory. It
may resume once the task is fulfilled.
Pre-empted: Kernel preempts an on-going process for allocation of
another process, while the first process is moving from kernel to user
mode.
Created: Process is newly created but not running. This is the start
state for all processes.
Zombie: Process has been executed thoroughly and exit call has
been enabled. The process, thereby, no longer exists. But, it stores a
statistical record for the process. This is the final state of all
processes.
PCB (Process Control Block),
Process Control Block is a data structure that contains information of
the process related to it. The process control block is also known as a
task control block, entry of the process table, etc.It is very important
for process management as the data structuring for processes is done
in terms of the PCB. It also defines the current state of the operating
system.

Pointer – It is a stack pointer which is required to be saved when the


process is switched from one state to another to retain the current
position of the process.
Process state – It stores the respective state of the process.
Process number – Every process is assigned with a unique id
known as process ID or PID which stores the process identifier.
Program counter – It stores the counter which contains the address
of the next instruction that is to be executed for the process.
Register – These are the CPU registers which includes: accumulator,
base, registers and general purpose registers.
Memory limits – This field contains the information about memory
management system used by operating system. This may include the
page tables, segment tables etc.
Open files list – This information includes the list of files opened
for a process.
Difference between Process and Thread:
S.
N Process Thread
O
Process means any Thread means a segment of a
1.
program is in execution. process.
The process takes more The thread takes less time to
2.
time to terminate. terminate.
It takes more time for
3. It takes less time for creation.
creation.
It also takes more time for It takes less time for context
4.
context switching. switching.
The process is less efficient Thread is more efficient in terms of
5.
in terms of communication. communication.
We don’t need multi programs in
Multiprogramming holds
action for multiple threads because
6. the concepts of multi-
a single process consists of multiple
process.
threads.
7. The process is isolated. Threads share memory.
A Thread is lightweight as each
The process is called the
8. thread in a process shares code,
heavyweight process.
data, and resources.
Process switching uses an Thread switching does not require
9. interface in an operating calling an operating system and
system. causes an interrupt to the kernel.
If one process is blocked
If a user-level thread is blocked,
then it will not affect the
10. then all other user-level threads are
execution of other
blocked.
processes
Interprocess Communication (IPC):

IPC is the mechanism provided by the operating system for


processes to communicate with each other.
Synchronization is important for orderly communication and can be
provided by the operating system or managed by processes.
Semaphore is a variable controlling access to shared resources, with
binary and counting types.
Mutual exclusion ensures only one process can enter a critical
section at a time, preventing race conditions.
Barriers synchronize processes, allowing them to wait until all reach
a certain point before proceeding.
Spinlocks involve busy waiting, where processes repeatedly check
for lock availability.
Approaches to IPC include pipes, sockets, files, signals, shared
memory, and message queues.
Pipes provide unidirectional data channels between processes.
Sockets facilitate communication between processes over a network.
Files allow multiple processes to access and share data.
Signals are system messages used for limited interprocess
communication.
Shared memory enables simultaneous access to memory by multiple
processes.
Message queues allow multiple processes to read and write data
without direct connection.
IPC mechanisms are widely used across operating systems for
efficient process communication.
race conditions in operating systems:
Race conditions occur when multiple processes or threads access
shared resources simultaneously without proper synchronization,
leading to unpredictable behavior and potential issues like data
corruption or crashes.
Lack of proper synchronization mechanisms increases the likelihood
of race conditions, as there is no control over the order of execution
for accessing and modifying shared data.
Common shared resources prone to race conditions include shared
memory, files, data structures, and hardware devices.
Reproducing and debugging race conditions can be challenging due
to their intermittent and non-deterministic nature, relying on specific
timing and execution interleaving.
Synchronization techniques such as locks, mutexes, semaphores, or
atomic operations can prevent race conditions by enforcing
exclusive access to shared resources.
Addressing race conditions requires thorough testing, debugging,
and careful design, as they are a common source of bugs and
vulnerabilities in concurrent software. Proper synchronization and
management of shared resources are crucial to mitigate race
condition risks.
Critical Section
The critical section problem is one of the classic problems in
Operating Systems. In operating systems, there are processes called
cooperative processes that share and access a single resource. In
these kinds of processes, the problem of synchronization occurs.
The critical section problem is a problem that deals with this
synchronization.
What is the Critical Section in OS?
Critical Section refers to the segment of code or the program which
tries to access or modify the value of the variables in a shared
resource.
The section above the critical section is called the Entry Section.
The process that is entering the critical section must pass the entry
section.
The section below the critical section is called the Exit Section.
The section below the exit section is called the Reminder Section
and this section has the remaining code that is left after execution.

;
Mutual Exclusion
Mutual exclusion, also known as a mutex, is a mechanism used to
prevent concurrent access to shared resources, ensuring that only one
thread can enter a critical section at a time.
It is implemented to avoid race conditions, which can occur when
multiple threads attempt to access and modify shared data
simultaneously.
Mutual exclusion ensures that a thread of execution does not enter
the critical section while another thread is already using it,
preventing data instability and ensuring data integrity.
In a mutex, when one thread is performing a write operation
(modifying the shared resource), other threads are not allowed to
access the same object until the writing thread has completed its
operation and released the object.
Mutexes are an essential tool in concurrency control, providing
synchronization and coordination among threads to prevent data
corruption, inconsistencies, and conflicts in shared resources.
There are four conditions applied to mutual exclusion, which are
mentioned below :
Mutual exclusion should be ensured in the middle of different
processes when accessing shared resources. There must not be two
processes within their critical sections at any time.
Assumptions should not be made as to the respective speed of the
unstable processes.
The process that is outside the critical section must not interfere with
another for access to the critical section.
When multiple processes access its critical section, they must be
allowed access in a finite time, i.e. they should never be kept waiting
in a loop that has no limits.
Mutual Exclusion with Busy Waiting
Mutual exclusion with busy waiting is a synchronization technique
used to implement mutual exclusion, where a process or thread
continuously checks for the availability of a lock or critical section.
Here are 5 points summarizing mutual exclusion with busy waiting:
Mutual exclusion with busy waiting involves a process or thread
repeatedly checking the status of a lock or critical section in a loop
until it becomes available.
When a process wants to enter a critical section, it checks if the lock
is available. If it is not, the process enters a loop and continuously
checks until the lock becomes available.
Busy waiting can be resource-intensive since the process is actively
waiting, consuming CPU cycles even when it is not performing
useful work.
Mutual exclusion with busy waiting is often used in situations where
the expected wait time for the lock is short and it is more efficient
than other synchronization techniques.
Care should be taken when implementing mutual exclusion with
busy waiting to avoid issues like starvation (a process being unable
to access the critical section) or priority inversion (lower-priority
processes blocking higher-priority ones).
lock variables:
Lock variables, or mutexes, are used for mutual exclusion and
control access to shared resources in concurrent programming.
Threads or processes acquire a lock variable before entering a
critical section and release it afterward.
Lock variables support atomic operations, ensuring that only one
thread can acquire the lock at a time.
Blocking locks suspend threads attempting to acquire the lock until
it becomes available, while non-blocking locks allow threads to
check the lock's status without blocking.
Lock variables are essential for preventing race conditions and
maintaining data consistency in multithreaded or multiprocessing
environments.
Careful usage of lock variables is crucial to avoid issues like
deadlocks and lock contention, ensuring effective and efficient
concurrent programming.
Peterson's algorithm (or Peterson's solution) is a
concurrent programming algorithm for mutual exclusion that
allows two or more processes to share a single-use resource
without conflict, using only shared memory for communication.
It was formulated by Gary L. Peterson in 1981.[1] While
Peterson's original formulation worked with only two
processes, the algorithm can be generalized for more than
two.[2]
The algorithm
The algorithm uses two variables: flag and turn. A flag[n] value
of true indicates that the process n wants to enter the critical
section. Entrance to the critical section is granted for process
P0 if P1 does not want to enter its critical section or if P1 has
given priority to P0 by setting turn to 0.

Peterson's algorithm
bool flag[2] = {false, false};
int turn;

P0: flag[0] = true; P1: flag[1] = true;


P0_gate: turn = 1; P1_gate: turn = 0;
while (flag[1] == true && while (flag[0] == true && turn
turn == 1) == 0)
{ {
// busy wait // busy wait
} }
// critical section // critical section
... ...
// end of critical section // end of critical section
flag[0] = false; flag[1] = false;

The algorithm satisfies the three essential criteria to solve the


critical-section problem. The while condition works even with
preemption.
The three criteria are mutual exclusion, progress, and
bounded waiting.
Since turn can take on one of two values, it can be replaced
by a single bit, meaning that the algorithm requires only three
bits of memory
Sleep and Wakeup
The concept of sleep and wake is very simple. If the critical
section is not empty then the process will go and
sleep. It will be waked up by the other process which is
currently executing inside the critical section so that
the process can get inside the critical section.
If there is no customer, then the barber sleeps in his own
chair.
When a customer arrives, he has to wake up the barber.
If there are many customers and the barber is cutting a
customer’s hair, then the remaining customers
either wait if there are empty chairs in the waiting room or they
leave if no chairs are empty.
Semaphores
Semaphores are integer variables used for process
synchronization in solving the critical section problem.
There are two types of semaphores: counting semaphores and binary
semaphores.
Counting semaphores have an unrestricted value domain and are
used to coordinate resource access. The count is incremented when
resources are added and decremented when resources are removed.
Binary semaphores have a restricted value domain of 0 and 1. The
wait operation waits for the semaphore to be 1, while the signal
operation sets the semaphore to 1 when it is 0.
Semaphores strictly enforce mutual exclusion, allowing only one
process into the critical section.
Semaphores are efficient and prevent resource wastage by
eliminating unnecessary busy waiting.
Semaphores are machine independent and implemented in the
machine independent code of the microkernel.
However, semaphores have some disadvantages:
They are more complicated and require careful implementation to
avoid deadlocks.
Semaphores can lead to loss of modularity in large-scale systems
due to the structure imposed by the wait and signal operations.
Priority inversion can occur where low priority processes access the
critical section before high priority processes.
Process Scheduling,
The process scheduling is the activity of the process manager
that handles the removal of the running process from the CPU
and the selection of another process on the basis of a
particular strategy.
Process scheduling is an essential part of a Multiprogramming
operating systems. Such operating systems allow more than
one process to be loaded into the executable memory at a
time and the loaded process shares the CPU using time
multiplexing.
Process Scheduling Goals
Fairness: Each process gets fair share of the CPU.
Efficiency: When CPU is 100% busy then efficiency is
increased.
Response Time: Minimize the response time for interactive
user.
Throughput: Maximizes jobs per given time period.
Waiting Time: Minimizes total time spent waiting in the ready
queue.
Turn Around Time: Minimizes the time between submission
and termination.
Batch System Scheduling (First ComeFirst Served,
Shortest Job First),
Batch System Scheduling
A Process Scheduler schedules different processes to be
assigned to the CPU based on particular scheduling
algorithms.
These algorithms are either non-preemptive or preemptive.
Non-preemptive algorithms are designed so that
once a process enters the running state, it cannot be
preempted until it completes its allotted time, whereas
the preemptive scheduling is based on priority where a
scheduler may preempt a low priority running
process anytime when a high priority process enters into a
ready state.
First Come First Serve (FCFS)
First Come First Serve (FCFS) is a system scheduling algorithm
used by operating systems to schedule processes or jobs based on
their arrival time. In FCFS, the process that arrives first is executed
first, and subsequent processes are executed in the order of their
arrival.
Here is a summary of the FCFS scheduling algorithm:
When a process enters the system, it is added to the end of the
process queue.
The operating system selects the process at the front of the queue for
execution.
The selected process is allocated the CPU and allowed to run until it
either completes its execution or gets blocked (e.g., waiting for I/O).
Once the process completes or gets blocked, the next process in the
queue is selected for execution.
This process continues until all processes in the queue have been
executed.
Advantages of FCFS Scheduling:
Simple and easy to understand and implement.
Guarantees fairness, as processes are executed in the order they
arrived.
Suitable for long-running processes that require a large amount of
CPU time.
Disadvantages of FCFS Scheduling:
May result in poor performance in terms of average waiting time,
especially if long processes arrive first (known as the "convoy
effect").
Inefficient utilization of CPU time, as short processes have to wait
for long processes to complete.
Shortest Job First
Shortest Job First (SJF) is a system scheduling algorithm used by
operating systems to schedule processes based on their burst time. In
SJF, the process with the shortest burst time is executed first, and
subsequent processes are executed in order of their burst times.
Here is a summary of the SJF scheduling algorithm:
When a process enters the system, its burst time is determined.
The operating system maintains a ready queue of processes waiting
to be executed.
The process with the shortest burst time is selected from the ready
queue for execution.
The selected process is allocated the CPU and allowed to run until it
either completes its execution or gets blocked (e.g., waiting for I/O).
Once the process completes or gets blocked, the next process with
the shortest burst time is selected for execution.
This process continues until all processes in the ready queue have
been executed.
Advantages of SJF Scheduling:
Minimizes the average waiting time, as shorter processes are
executed first.
Efficient utilization of CPU time, as shorter processes are completed
earlier, allowing more processes to be executed.
Suitable for scenarios where burst times are known in advance or
can be accurately estimated.
Disadvantages of SJF Scheduling:
Requires prior knowledge or estimation of burst times, which may
not always be available or accurate.
Can lead to starvation for long processes if shorter processes keep
arriving.
Round Robin (RR) scheduling
Round Robin (RR) scheduling is a system scheduling algorithm
used by operating systems to allocate CPU time among multiple
processes in a time-sliced manner. In RR scheduling, each process is
assigned a fixed time quantum or time slice, and they take turns
executing for that quantum until their completion or the quantum
expires.
Here is a summary of the Round Robin scheduling algorithm:
The operating system maintains a ready queue of processes waiting
to be executed.
Each process in the ready queue is assigned a fixed time quantum.
The operating system selects the process at the front of the ready
queue for execution.
The selected process is allocated the CPU and allowed to run for its
time quantum.
If the process completes within its time quantum, it is removed from
the ready queue.
If the process does not complete within its time quantum, it is moved
to the back of the ready queue.
The next process in the ready queue is selected for execution.
Steps 4 to 7 are repeated until all processes have been executed.
Advantages of Round Robin Scheduling:
Fair allocation of CPU time among processes.
Provides responsiveness, as each process gets a chance to execute
within its time quantum.
Suitable for scenarios with interactive processes or real-time
requirements.
Disadvantages of Round Robin Scheduling:
May result in increased context switching overhead due to frequent
process switching.
Inefficient for long-running processes, as they are interrupted at the
end of each time quantum.
Performance can be impacted if the time quantum is set too short or
too long.

Overall, Round Robin is a popular scheduling algorithm that offers


fair CPU time allocation among processes. It provides
responsiveness and is suitable for scenarios where interactive
processes need to be given equal opportunities to execute. However,
it may not be the most efficient choice for long-running processes or
scenarios with strict performance requirements. The selection of an
appropriate time quantum is crucial for optimizing the balance
between responsiveness and overhead.
Deadlocks

Deadlock is a state in a computer system where multiple processes


are unable to proceed.
It occurs when each process is waiting for a resource that is held by
another process.
Deadlock is characterized by a circular dependency of resource
requirements, creating a situation where no process can make
progress.
Four necessary conditions for deadlock are mutual exclusion, hold
and wait, no preemption, and circular wait.
Detecting and resolving deadlocks is crucial to ensure the proper
functionality and efficiency of computer systems.
Pre-emptable Resources:
Definition: Resources that can be forcefully taken away from a
process by the system.
Examples: CPU time, memory, I/O devices.
Advantages: Better resource utilization and responsiveness.
Usage: Common in real-time systems with strict timing
requirements.
Implementation: Managed through scheduling algorithms and
interrupts.
Non-pre-emptable Resources:
Definition: Resources that cannot be forcefully taken away from a
process by the system.
Examples: Files, databases, hardware peripherals.
Advantages: Stability and consistency for exclusive access.
Usage: Critical operations to prevent data corruption or loss.
Implementation: Synchronization mechanisms like locks and
semaphores to ensure exclusive access and prevent conflicts.
deadlock modeling in operating systems in bullet points:
Deadlock modeling is the process of analyzing and representing
potential deadlocks in a system.
Deadlock refers to a situation where multiple processes are unable to
proceed because each is waiting for a resource held by another
process.
The goal of deadlock modeling is to identify and prevent deadlock
situations in a system.
Resource Allocation Graph (RAG) is a graphical representation used
to analyze resource allocation and identify potential deadlocks.
Deadlock detection algorithms periodically examine the resource
allocation state to detect the presence of a deadlock.
State Transition Diagrams represent process states and events to
analyze potential deadlocks.
Deadlock prevention and resolution techniques include resource
allocation policies and deadlock avoidance algorithms.
Resource allocation policies, such as the Banker's algorithm, ensure
safe resource allocation.
Deadlock avoidance algorithms use heuristics to dynamically
allocate resources and avoid potential deadlocks.
Deadlock modeling helps in designing and analyzing systems to
manage resources effectively and prevent system-wide deadlocks.
Conditions for deadlock
Mutual Exclusion:
At least one resource in the system is non-sharable, meaning that
only one process can use it at any given time.
Examples of such resources include printers, tape drives, and
exclusive access to specific sections of memory.
Mutual exclusion is necessary to maintain data integrity and prevent
concurrent access issues.
Hold and Wait:
Processes hold at least one resource while waiting to acquire
additional resources held by other processes.
A process that is currently holding resources can request new
resources while retaining the ones it already possesses.
This condition can lead to resource allocation inefficiency if
processes hold resources for an extended period without releasing
them.
No Preemption:
Resources cannot be forcibly taken away from a process; they can
only be released voluntarily by the process holding them.
Preemption would involve forcibly interrupting a process, taking
away its resources, and reallocating them to other processes.
In many scenarios, preemption is not feasible or desirable due to the
potential for data corruption or process instability.
Circular Wait:There must exist a circular chain of two or more
processes, where each process is waiting for a resource held by the
next process in the chain.For example, Process A is waiting for a
resource held by Process B, Process B is waiting for a resource held
by Process C, and so on until Process N is waiting for a resource
held by Process A.This circular dependency creates a deadlock
situation where no process can proceed as they are all waiting for
resources that will never be released.
deadlock handling strategies:
Deadlock Prevention:
Deadlock prevention aims to eliminate one or more of the necessary
conditions for deadlock to occur.
Strategies include resource allocation policies and techniques that
ensure the system does not enter a deadlock-prone state.
Examples include the Banker's algorithm, which employs resource
allocation algorithms to check for safe states before granting
resource requests.
Deadlock Avoidance:
Deadlock avoidance involves using algorithms to dynamically
analyze resource requests and avoid potential deadlock situations.
Resources are allocated to processes based on prediction and
estimation to prevent the occurrence of deadlock.
Techniques such as the Resource Allocation Graph (RAG) and state
transition diagrams can be used to make decisions on resource
allocation.
Deadlock Detection and Recovery:
Deadlock detection involves periodically examining the system's
resource allocation state to detect the presence of a deadlock.
Various algorithms, such as the Banker's algorithm, can be used to
detect and identify deadlocks.
Once a deadlock is detected, recovery strategies may be
implemented to resolve the deadlock, such as process termination,
resource preemption, or rollback and restart of processes.
Deadlock Ignorance (No Prevention or Handling):
Some systems choose to ignore deadlocks altogether, either due to
the belief that deadlocks are rare or because the cost of
implementing deadlock handling strategies outweighs the potential
impact of deadlocks.In such cases, the system relies on manual
intervention or system restart to resolve deadlocks if they occur.
ostrich algorithm
The ostrich algorithm refers to sticking one's head in the sand and
ignoring a problem, often applied metaphorically to deadlock
situations.
It is a method of solving a problem by pretending it doesn't exist,
specifically used to ignore deadlocks.
The ostrich algorithm is commonly used by end-users and may
involve rebooting the system to address deadlocks.
Scientists generally advocate for deadlock prevention as the most
efficient method.
Engineers, on the other hand, may prioritize other system issues over
deadlocks, considering their relatively infrequent occurrence.
Some operating systems may suffer from undetected or automatic
resolution of deadlocks.
Finite resources in the system, such as process table slots, file
openings, and swap space, can contribute to deadlock occurrences.
Many operating systems, including UNIX and Windows, initially
ignore deadlocks and assume a single-process restriction for
simplicity.
Trade-offs exist between correctness and convenience when
choosing deadlock resolution methods.
Advantages of Ignoring Deadlock:Simplicity: Ignoring deadlock
simplifies the design and implementation of the operating system.
Performance: Avoiding deadlock detection and recovery
mechanisms can improve system performance by reducing resource
overhead.
Disadvantages of Ignoring Deadlock:Unpredictability: Ignoring
deadlock can lead to unpredictable system behavior, compromising
reliability and stability.System crashes: If a deadlock occurs and is
not handled, it can cause system crashes, resulting in data loss and
other issues.Reduced availability: Deadlocks can block processes,
reducing system availability and impacting user experience.
Recovering from Deadlock,
Deadlock Recovery through Preemption:
Difficult or sometimes impossible due to the nature of resources.
Involves taking a resource away from one process and allocating it
to another.
Highly dependent on the type of resource and process sensitivity to
resource interruption.
Deadlock Recovery through Rollback:
When a deadlock is detected, the system identifies which resources
are needed.
Processes that own a needed resource are rolled back to a previous
checkpoint.
Rolled-back processes are restored to a state before acquiring other
resources, allowing them to proceed.
Deadlock Recovery through Killing Processes:
Basic method of deadlock recovery.
Involves terminating one or more processes involved in the
deadlock.
Terminated processes release their held resources, resolving the
deadlock.
Terminated processes can be restarted from the beginning without
significant consequences.
prevent deadlocks in operating systems:
Mutual Exclusion:
Ensure that at least one resource in the system is shareable and can
be used by multiple processes simultaneously.
This prevents the mutual exclusion condition required for deadlocks
to occur.
Hold and Wait:
Implement a strategy where processes request and acquire all the
required resources upfront before execution starts.
Processes should not hold any resources while waiting for additional
resources to be allocated.
This helps to avoid the hold and wait condition that contributes to
deadlocks.
No Preemption:
Prevent resource preemption, which means resources cannot be
forcibly taken away from a process.
If a process holding resources requires additional resources, it
releases its held resources and restarts the acquisition process.
This avoids the circular wait condition necessary for deadlocks.
Resource Ordering:
Define a total ordering of resources and ensure that processes always
request resources in a consistent order.
This helps to prevent the circular wait condition by ensuring that
processes cannot hold one resource while waiting for another that is
held by another process.
deadlock detection and recovery
Deadlock Detection:
Detecting deadlocks involves analyzing the resource allocation state
and dependencies between processes and resources.
For systems with single-instance resources, the presence of a cycle
in the resource allocation graph indicates a deadlock.
For systems with multiple-instance resources, the Wait-For Graph
algorithm is used to detect deadlocks.
Deadlock detection algorithms periodically check for the presence of
cycles or dependencies to identify deadlock situations.
Deadlock Recovery:
Killing Processes: One approach to deadlock recovery is to
terminate one or more processes involved in the deadlock, releasing
their held resources. This breaks the circular dependency and allows
other processes to continue.
Resource Preemption: Deadlock recovery can involve preempting
resources from processes involved in the deadlock. These resources
are reallocated to other waiting processes, resolving the deadlock.
Rollback and Restart: In some cases, a system may use rollback and
restart techniques. Processes are rolled back to a previous state
before acquiring resources, and then they are restarted from that
point.
Concurrency Control: Deadlock prevention through concurrency
control mechanisms, such as locking protocols, can help avoid
deadlocks by managing resource access and ensuring consistency.
Memory management
Memory management is a crucial process that optimizes system
performance by coordinating and controlling computer memory.
It encompasses hardware components like RAM chips, memory
caches, and SSDs, as well as the operating system and applications.
In hardware, memory management involves the physical storage of
data and the allocation of memory blocks.
In the operating system, memory management focuses on assigning
specific memory blocks to individual programs as user demands
change.
At the application level, memory management ensures that each
running program has adequate memory for its objects and data
structures, combining tasks such as allocation and recycling.
memory manager
A memory manager is a software utility that works alongside the
operating system to enhance memory management.
It aids in efficient memory utilization by implementing various
techniques and algorithms to allocate and deallocate memory.
Memory managers often include features like flushing out unused
memory segments, improving overall system performance.
They help ensure that memory is allocated appropriately to running
programs and prevent issues like memory leaks or fragmentation.
Memory managers are a standard component of modern operating
systems, providing essential functionality for efficient memory
management.
MEMORY HIERACHY
Memory hierarchy is designed to minimize access time by
organizing memory into different levels with varying speeds and
sizes.
It is based on the principle of locality of references, which states that
programs tend to access data that is spatially or temporally close to
previously accessed data.
Balance cost and capacity by using different types of memory with
varying sizes and costs.
Improve overall system performance by efficiently managing data
storage and retrieval across different memory levels.
Registers:
Registers are small, high-speed storage units located within the
CPU.
They are built directly into the processor and provide extremely fast
access to data and instructions.
Registers store the most frequently accessed data and instructions
that the CPU is actively working on.
Registers have the smallest capacity among all memory levels,
typically measured in bytes.
They play a crucial role in executing instructions and performing
calculations within the CPU.
Cache Memory:
Cache memory is a smaller, faster memory that sits between the
CPU and main memory.
It serves as a buffer to store frequently accessed data and instructions
to reduce the average access time.
Cache memory operates based on the principle of locality of
references, exploiting the tendency of programs to access nearby
data.
It is divided into multiple levels, such as L1, L2, and L3 cache, each
with increasing capacity but slightly slower access times.
Cache memory is more expensive than main memory but faster to
access, helping to improve overall system performance.
Main Memory (RAM):
Main memory, or random-access memory (RAM), is the primary
memory used by the computer system.
It holds data and instructions that are actively used by the CPU
during program execution.
Main memory is larger in capacity compared to cache memory but
has slower access times.
It is a volatile memory, meaning its contents are lost when the power
is turned off.
Main memory stores both the operating system and user applications
and provides the working space for the CPU.
Magnetic Disk (Hard Disk Drives):
Magnetic disks, commonly known as hard disk drives (HDDs), are
non-volatile storage devices.
They use magnetic storage technology to store data on rotating disks
coated with a magnetic material.
Magnetic disks offer high capacity and are commonly used for long-
term storage of files, applications, and the operating system.
They have slower access times compared to cache and main memory
but provide persistent storage even when the power is off.
Magnetic disks are widely used in computers and provide a cost-
effective storage solution.
Optical Disk (CD/DVD/Blu-ray):
Optical disks, such as CDs, DVDs, and Blu-ray discs, are non-
volatile storage media.
They store data using microscopic indentations on the surface of the
disk, which can be read by a laser beam.
Optical disks have a higher capacity than magnetic disks and are
commonly used for distribution and archival purposes.
They have slower access times compared to magnetic disks and are
read-only (CD/DVD) or read-write (Blu-ray) depending on the type.
Optical disks are portable, inexpensive, and widely used for storing
multimedia, software, and backup data.
Magnetic Tape:
Magnetic tape is a sequential access storage medium that uses a
magnetic coating on a long plastic strip.
It is a high-capacity storage solution used for backup, archival, and
offline data storage.
Magnetic tape offers very low cost per unit of storage and can store
large amounts of data.
However, it has the slowest access times among the mentioned
storage media due to the sequential nature of data retrieval.
Magnetic tape is commonly used for long-term data retention and is
less suitable for frequent data access.
Characteristics of Memory Hierarchy
Capacity: It is the global volume of information the memory can
store. As we move from top to bottom in the Hierarchy, the capacity
increases.
Access Time: It is the time interval between the read/write request
and the availability of the data. As we move from top to bottom in
the Hierarchy, the access time increases.
Performance: Earlier when the computer system was designed
without a Memory Hierarchy design, the speed gap increased
between the CPU registers and Main Memory due to a large
difference in access time. This results in lower performance of the
system and thus, enhancement was required. This enhancement was
made in the form of Memory Hierarchy Design because of which the
performance of the system increases. One of the most significant
ways to increase system performance is minimizing how far down
the memory hierarchy one has to go to manipulate data.
Cost Per Bit: As we move from bottom to top in the Hierarchy, the
cost per bit increases i.e. Internal Memory is costlier than External
Memory.
Monoprogramming memory management
Monoprogramming memory management allocates entire memory to
a single program.
Static memory allocation divides memory into fixed partitions for
specific purposes.
Only one program executes at a time, utilizing all available memory
resources.
No memory fragmentation occurs due to predefined and dedicated
memory partitions.
Limited memory usage restricts program size and complexity within
allocated space.
Memory Management in Multiprogramming
Multiprogramming memory management shares memory among
multiple programs concurrently.
Dynamic memory allocation allows programs to request and release
memory as needed.
Memory is divided into variable-sized partitions based on program
requirements.
Memory fragmentation can occur due to the dynamic allocation and
deallocation of memory.
Techniques like paging and virtual memory are used to efficiently
manage memory.
Multiprogramming with Fixed Partition
Multiprogramming with fixed partition is a memory management
technique where memory is divided into fixed-size partitions or
sections.
Each partition is assigned to a specific program, allowing multiple
programs to reside in memory simultaneously.
The number and size of partitions are predetermined and remain
constant.
Programs are loaded into the available partitions based on their size,
and multiple programs can be executed concurrently.
Fixed partition allocation can lead to internal fragmentation, where
the allocated partition may be larger than the actual size of the
program, wasting some memory space.
It requires advanced scheduling algorithms to manage the execution
and swapping of programs in and out of partitions.
Adding or removing programs from memory may require
rearranging partitions or shifting programs to ensure optimal
utilization of memory resources.
Multiprogramming with Variable Partition in
Multiprogramming with variable partition is a memory management
technique where memory is divided into variable-sized partitions
based on program requirements.
Each program is allocated memory dynamically, allowing efficient
utilization of available memory space.
The size of partitions can vary depending on the size of the program
being loaded.
Programs are loaded into the smallest available partition that can
accommodate their size.
Variable partition allocation reduces internal fragmentation by
matching the partition size closely to the program's memory
requirements.
Memory allocation and deallocation are dynamic, allowing programs
to request and release memory as needed.
It requires efficient memory management algorithms, such as best-fit
or worst-fit, to allocate and deallocate memory partitions effectively.
Relocation:
Relocation is a process in operating systems that allows programs to
be loaded and executed at different memory locations.
It enables flexibility in memory allocation, as programs can be
loaded into any available memory space.
Relocation involves modifying the program's memory references
and addressing to reflect the actual memory location where it is
loaded.
It ensures that programs can be executed regardless of their specific
memory location, making efficient use of available memory
resources.
Relocation is essential for multiprogramming environments where
multiple programs may need to be loaded and executed concurrently.
Protection:
Protection is a crucial aspect of operating system design that ensures
the security and integrity of programs and data.
It involves implementing mechanisms to control and restrict access
to memory, files, and other system resources.
Protection mechanisms prevent unauthorized access, modification,
or execution of programs and data by enforcing access rights and
permissions.
It provides isolation and prevents interference between different
programs running concurrently, maintaining system stability and
security.
Protection mechanisms include user authentication, access control
lists, file permissions, and memory segmentation to enforce security
and maintain the integrity of the system.
Coalescing:
Coalescing is a memory management technique used to merge
adjacent free memory blocks into larger contiguous blocks.
It helps reduce memory fragmentation by consolidating fragmented
free memory regions into larger, more usable chunks.
Coalescing is typically performed during memory deallocation when
a memory block becomes free.
By merging adjacent free blocks, it increases the likelihood of
accommodating larger memory allocations in the future.
Coalescing improves memory utilization and can enhance the
efficiency of memory allocation algorithms.
Compaction:
Compaction is a memory management technique that involves
rearranging the allocated memory blocks to create a larger
contiguous free memory region.
It is typically performed when memory becomes fragmented,
resulting in scattered free blocks and inefficient memory utilization.
Compaction involves moving allocated memory blocks and
adjusting memory references to create a compacted, contiguous free
memory area.
It helps address external fragmentation by reducing the number of
small, non-contiguous free memory regions.
Compaction may be resource-intensive and requires careful handling
of memory references to ensure data integrity and program
correctness.
Virtual Memory:
Virtual memory is a memory management technique used by
operating systems to provide the illusion of having more physical
memory than actually available.
It allows programs to access a larger address space than the physical
memory by using disk space as an extension of RAM.
Virtual memory enables efficient multitasking by allowing multiple
programs to run simultaneously, each with its own virtual address
space.
It provides memory isolation, protecting programs from interfering
with one another and enhancing system stability and security.
Virtual memory relies on the concept of virtual addresses, which are
translated to physical addresses by the memory management unit
(MMU) of the CPU.
The translation process between virtual addresses and physical
addresses involves the use of data structures called page tables.
Virtual memory plays a vital role in memory-demanding
applications, as it allows the system to handle memory-intensive
tasks by swapping data between RAM and disk.
Paging:
Paging is a memory management scheme used in virtual memory
systems.
It divides both physical and virtual memory into fixed-size blocks
called pages.
The page size is typically a power of two, such as 4KB or 8KB.
Programs are divided into fixed-size blocks called pages, and these
pages are loaded into physical memory as needed.
Paging allows non-contiguous allocation of memory, reducing
external fragmentation.
It simplifies memory management by treating memory as a
collection of pages rather than a continuous address space.
Paging helps improve memory utilization and enables efficient
memory allocation and deallocation.
Page Tables:
Page tables are data structures used in virtual memory systems to
translate virtual addresses to physical addresses.
Each process has its own page table, which maps virtual page
numbers to corresponding physical page frames.
The page table is maintained by the operating system and is stored in
memory.
The page table entry contains information such as the physical
address of the corresponding page frame and various flags for access
permissions, caching, and other attributes.
When a program accesses a virtual address, the page table is
consulted to determine the corresponding physical address.
Page Fault:
A page fault occurs when a program references a virtual page that is
not currently in physical memory.
It is a form of exception that triggers the operating system's handling
routine.
When a page fault occurs, the operating system checks if the
required page is present in physical memory.
If the page is not present, it is fetched from disk into a free page
frame in physical memory.
The page table is updated to reflect the new mapping, and the
program is resumed from the point of interruption.
Page faults are a normal part of virtual memory operation and are
managed transparently by the operating system.
If physical memory is full and no free page frames are available, the
operating system may need to select a victim page to evict from
memory and make room for the requested page.
Page Replacement algorithms:
Optimal Page Replacement algorithm:
The Optimal Page Replacement algorithm is an idealized page
replacement algorithm used for theoretical analysis and performance
comparison.
It selects the page that will not be used for the longest duration in the
future for replacement.
The algorithm assumes perfect knowledge of future memory
references, which is not practically achievable.
It requires analyzing the entire sequence of memory references in
advance to determine the optimal replacement choice.
By replacing the page that will be accessed farthest in the future, it
aims to minimize the overall number of page faults.
The Optimal algorithm serves as a benchmark for evaluating other
page replacement algorithms and their performance.
In real-world scenarios, it is not feasible to implement the Optimal
algorithm due to the lack of future reference information.
Despite its infeasibility in practical implementations, the Optimal
algorithm helps understand the upper limit of achievable
performance for page replacement strategies.
Not Recently Used (NRU) Page Replacement algorithm:
The Not Recently Used (NRU) Page Replacement algorithm is a
simple and low-overhead page replacement algorithm.
It categorizes pages into four classes based on their recent use and
modification status.
The four classes are: (i) Not referenced, not modified, (ii) Not
referenced, modified, (iii) Referenced, not modified, and (iv)
Referenced, modified.
When a page needs to be replaced, the NRU algorithm selects a page
from the lowest numbered non-empty class.
The goal is to replace pages that have not been recently referenced to
make room for new pages.
If possible, the algorithm selects a page from a lower class (less
recently used and not modified) to avoid replacing frequently used
or modified pages.
NRU provides a simple and efficient way to avoid replacing
frequently used pages while still allowing some flexibility in the
replacement process.
However, the NRU algorithm does not make optimal decisions and
may suffer from inefficiencies compared to more advanced page
replacement algorithms.
First-In-First-Out (FIFO) Page Replacement algorithm:
The First-In-First-Out (FIFO) Page Replacement algorithm is one of
the simplest and intuitive page replacement algorithms.
It operates on the principle that the page that has been in memory the
longest should be replaced first.
The algorithm maintains a queue or a list to keep track of the order
in which pages were loaded into memory.
When a page needs to be replaced, the FIFO algorithm selects the
page at the front of the queue (oldest page) for replacement.
The selected page is removed from memory, and the new page is
brought in and added to the end of the queue.
FIFO does not consider the frequency of page usage or the relevance
of the page to the program's current state.
It suffers from the "Belady's Anomaly" phenomenon, where
increasing the number of page frames can lead to more page faults.
Despite its simplicity, FIFO can result in poor performance if the
page access pattern does not align well with the FIFO ordering of
pages.
Clock Page Replacement algorithm:
The Clock Page Replacement algorithm is a modified version of the
First-In-First-Out (FIFO) algorithm.
It utilizes a circular list or clock hand to keep track of the pages in
memory.
Each page in memory is associated with a reference bit, indicating
whether it has been recently referenced.
When a page fault occurs and a page needs to be replaced, the clock
hand moves through the circular list of pages.
Pages with their reference bit set to 0 are considered for
replacement, as they have not been recently referenced.
If the reference bit of a page is encountered and found to be 1, it is
cleared, and the clock hand continues its movement.
The process of clearing the reference bits periodically prevents
pages from being protected indefinitely.
The Clock algorithm provides a balance between performance and
simplicity, avoiding the Belady's Anomaly and reducing the
overhead compared to more complex algorithms.
Segmentation in OS (Operating System) in 5 points:
Segmentation is a memory management technique used by operating
systems to divide a process into logical segments or sections.
Each segment represents a specific part of a process, such as code,
data, stack, or heap.
Segmentation allows for flexible memory allocation, as different
segments can grow or shrink dynamically based on program
requirements.
Each segment is assigned a unique segment identifier (segment
number or base address) and a length.
Segmentation helps in organizing and accessing different parts of a
program efficiently, facilitating memory protection and sharing
among processes.
Virtual Memory Segmentation
Virtual memory segmentation is a memory management technique
that combines the benefits of both virtual memory and segmentation.
It divides the logical address space of a process into segments,
similar to traditional segmentation, and maps them to physical
memory or disk.
Each segment represents a distinct portion of the process, such as
code, data, stack, or heap.
Segments are not required to be contiguous in physical memory,
allowing for efficient utilization of memory resources.
Virtual memory segmentation enables the illusion of a larger address
space for each process, even if physical memory is limited.
The mapping of segments to physical memory or disk is managed by
the operating system using page tables or segment tables.
Virtual memory segmentation helps in providing memory protection,
sharing, and dynamic memory allocation while overcoming the
limitations of fixed-size partitions or fixed-size pages in traditional
memory management schemes.
Simple Segmentation
Simple Segmentation is a basic memory management technique that
divides the memory into logical segments of varying sizes.
Each segment represents a specific portion of a program, such as
code, data, stack, or heap.
Segments are defined based on their functional requirements and can
be of different sizes.
Simple Segmentation does not involve the use of virtual memory or
paging techniques.
Memory allocation is performed at the segment level, with each
segment assigned a specific starting address.
Simple Segmentation allows for flexibility in memory allocation, as
segments can grow or shrink dynamically based on program
requirements.
However, it may suffer from external fragmentation, where free
memory blocks are scattered throughout the memory space, making
it challenging to allocate contiguous segments when needed.
Importance of Segmentation
Memory Organization: Segmentation provides a logical
organization of memory, dividing it into distinct segments
representing different parts of a program. This helps in managing
and accessing memory more efficiently.
Memory Protection: Segmentation allows for memory protection
by assigning different access rights and permissions to each
segment. This prevents unauthorized access or modification of
critical program areas.
Modularity and Code Reusability: Segmentation promotes
modularity in programming by separating different components of a
program into segments. This enables code reusability and simplifies
program maintenance and updates.
Dynamic Memory Allocation: Segmentation allows for dynamic
memory allocation at the segment level. Segments can grow or
shrink as needed, providing flexibility in managing memory
resources based on program requirements.
Sharing of Code and Data: Segmentation facilitates code and data
sharing among multiple processes. Multiple processes can reference
the same segment, reducing memory consumption and enhancing
system efficiency.
Virtual Memory Management: Segmentation is a fundamental
component of virtual memory systems. It enables the mapping of
logical segments to physical memory or disk, allowing the illusion
of a larger address space than the available physical memory.
Efficient Memory Utilization: Segmentation helps in efficient
memory utilization by eliminating internal fragmentation. Each
segment can occupy just the required amount of memory, reducing
wastage of memory resources.
Support for Complex Applications: Segmentation is essential for
supporting complex applications with varying memory
requirements. It enables the management of large code bases,
extensive data structures, and multiple threads or processes within a
unified memory framework.
Drawbacks of Segmentation
External Fragmentation: Segmentation can lead to external
fragmentation, where free memory blocks become scattered
throughout the memory space. This can make it challenging to
allocate contiguous segments, resulting in inefficient memory
utilization.
Variable Segment Sizes: Managing segments of varying sizes can
introduce complexity in memory allocation and deallocation
algorithms. It requires additional overhead and bookkeeping to keep
track of available memory segments.
Compaction Overhead: Compacting memory to eliminate external
fragmentation can be computationally expensive and may impact
system performance. It requires moving segments and updating
memory references, resulting in increased overhead.
Lack of Locality: Segmentation does not inherently provide spatial
locality, as segments can be located randomly in memory. This can
impact cache efficiency and increase memory access times.
Limited Sharing: Sharing segments among different processes can
be challenging. Fine-grained segment-level sharing may require
complex synchronization mechanisms, reducing the advantages of
shared memory.
Difficulty in Addressing: Managing variable segment sizes and
addressing within segments can be complex. The need for explicit
address translation or additional tables can introduce overhead and
increase memory access time.
Fragmentation of Virtual Address Space: Segmentation can lead
to fragmentation of the virtual address space, making it difficult to
allocate large contiguous blocks of memory for certain operations or
data structures. This can limit the scalability and performance of
applications with large memory requirements.
file Management
Operating system is used to manage files of computer system. A file
is collection of specific information
stored in the memory of computer system. File management is
defined as the process of manipulating files
in computer system, it management includes the process of creating,
modifying and deleting the files.
file system
file system organizes and names files, providing a logical structure
for storage and retrieval of data.
Without a file system, it would be difficult to isolate and identify
individual files.
File systems are modeled after paper-based filing systems and use
logic-based methods for storing and retrieving documents.
Different operating systems have their own file system
implementations, such as Microsoft Windows, macOS, and Linux.
Major types of file systems include distributed file systems, disk-
based file systems, and special purpose file systems, each designed
for specific applications.
File System Layout
Files and Directories: The file system consists of files and
directories, representing the actual data and the organization of data
within the file system.
Boot Block: The boot block is a crucial component located at the
beginning of the file system. It contains the boot loader and other
essential information for booting the operating system.
Superblock: The superblock holds critical metadata about the file
system, such as its type, size, status, and other parameters. It serves
as a central reference point for accessing and managing the file
system.
Bitmaps: Bitmaps are used to track the allocation status of disk
blocks or inodes. They provide a map indicating which blocks or
inodes are allocated or free within the file system.
Allocation Groups: The file system is divided into one or more
allocation groups, which contain disk inodes and fragments. These
groups help in organizing and managing the file system's data and
allocating resources efficiently. Each file system occupies one
logical volume.
File Types
Files can be classified into various types based on their content and
purpose. Common file types include text files, image files, audio
files, video files, executable files, and compressed files.
Each file type has its own format and may require specific software
or applications to open, edit, or execute them. File types are typically
identified by their file extensions, such as .txt for text files or .jpg for
image files.

File Structure
A File Structure needs to be predefined format in such a way that an
operating system understands. It has an
exclusively defined structure, which is based on its type.
Three types of files structure in OS:
A text file: It is a series of characters that is organized in lines.
An object file: It is a series of bytes that is organized into blocks.
A source file: It is a series of functions and processes.
File Access
File access is a process that determines the way that files are
accessed and read into memory. Generally, a
single access method is always supported by operating systems.
Though there are some operating system
which also supports multiple access methods.
Three file access methods are:
 Sequential access
 Direct random access
 Index sequential access
Sequential Access
In this type of file access method, records are accessed in a certain
pre-defined sequence. In the sequential
access method, information stored in the file is also processed one
by one. Most compilers access files using
this access method.
Direct Random Access
The random access method is also called direct random access. This
method allow accessing the record
directly. Each record has its own address on which can be directly
accessed for reading and writing.
Index Sequential Access
This type of accessing method is based on simple sequential access.
In this access method, an index is built
for every file, with a direct pointer to different memory blocks. In
this method, the Index is searched
sequentially, and its pointer can access the file directly. Multiple
levels of indexing can be used to offer
greater efficiency in access. It also reduces the time needed to access
a single record.
File Attributes
A file has a name and data. Moreover, it also stores Meta
information like file creation date and time, current size, last
modified date, etc. All this information is called the attributes of a
file system.
Here, are some important File attributes used in OS:
Name: It is the only information stored in a human-readable form.
Identifier: Every file is identified by a unique tag number within a
file system known as an identifier.
Location: Points to file location on device.
Type: This attribute is required for systems that support various
types of files.
Size: Attribute used to display the current file size.
Protection: This attribute assigns and controls the access rights of
reading, writing, and executing the file.
Time, date and security: It is used for protection, security, and also
used for monitoring
File Operations
A file is an abstract data type. OS can provide system calls to create,
write, read, reposition, delete and
truncate files.
Creating a file – First space in the file system must be found for the
file. Second, an entry for the new file
must be made in the directory.
Writing a file – To write a file, specify both the name of the file and
the information to be written to the
file. The system must keep a write pointer to the location in the file
where the next write is to take place.
Reading a file – To read from a file, directory is searched for the
associated entry and the system needs to
keep a read pointer to the location in the file where the next read is
to take place. Because a process is either
reading from or writing to a file, the current operation location can
be kept as a per process current file
position pointer.
Repositioning within a file – Directory is searched for the
appropriate entry and the current file position
pointer is repositioned to a given value. This operation is also known
as file seek.Deleting a file – To delete a file, search the directory for
the named file. When found, release all file space
and erase the directory entry.
Truncating a file – User may want to erase the contents of a file but
keep its attributes. This functionallows all attributes to remain
unchanged except for file length
Directory
Directory can be defined as the listing of the related files on the disk.
The directory may store some or the
entire file attributes.
To get the benefit of different file systems on the different operating
systems, a hard disk can be divided into
the number of partitions of different sizes. The partitions are also
called volumes or mini disks.
Each partition must have at least one directory in which, all the files
of the partition can be listed. A
directory entry is maintained for each file in the directory which
stores all the information related to that file.
Single-level directory:
Definition (5 points):
A directory structure where all files are contained within a single
directory.
It is the simplest form of directory organization.
All files have unique names within the directory.
Easy to implement and understand.
Limited scalability and potential for name collisions.
Advantages (4 points):
Easy implementation and support.
Faster searching for smaller files.
Simple file operations like creation, searching, deletion, and
updating.
Logical organization of files within a single directory.
Disadvantages (4 points):
Potential for name collisions when multiple users have files with the
same name.
Slow searching as the directory grows larger.
Inability to group similar files together or create subdirectories.
Limited scalability for managing a large number of files or users.
Two-level directory:
Definition (5 points):
A directory structure where each user has a separate user files
directory (UFD).
Users' UFDs have similar structures and list only their own files.
The system's master file directory (MFD) is searched to validate user
IDs.
Provides a solution to the problem of file name conflicts in a single-
level directory.
Users cannot create subdirectories but can have more than two files
with the same name.
Advantages (4 points):
Avoids name collisions among users' files.
Provides security by preventing access to other users' files.
Easy searching of files within a user's directory.
Each user has their own dedicated directory for better file
organization.
Disadvantages (4 points):
Inability to share files among users.
Users cannot create subdirectories within their directories.
Lack of scalability for managing a large number of files or users.
Potential for slower searching as the number of files within each
user's directory increases.
Tree Structure/Hierarchical Structure:
Definition (5 points):
A directory structure resembling an upside-down tree, with the root
directory at the top.
Users can create subdirectories and store files within their
directories.
Each user has their own directory, and they cannot modify the root
directory data.
Users do not have access to other users' directories, enhancing
privacy and security.
Allows for a more flexible and scalable organization of files and
subdirectories.
Advantages (4 points):
Allows the creation of subdirectories for better file organization.
Easier searching within the directory structure.
Facilitates file sorting and organization, including important and
unimportant files.
More scalable than single-level or two-level directories for
managing large amounts of data.
Disadvantages (4 points):
Inability to share files among users within the directory structure.
Complicated searching if there are many levels of subdirectories.
Users cannot modify the root directory data.
Files may need to be split across multiple directories if they exceed
the capacity of a single directory.

L
Contiguous Allocation:
Definition (8 points):
Contiguous allocation is a file system implementation method where
files are stored in consecutive blocks on a storage medium.
In this method, each file occupies a contiguous block of storage
space.
The starting location of a file's storage block and its length are
recorded in a file allocation table or similar data structure.
The contiguous blocks are allocated when a file is created and
released when the file is deleted.
This method is commonly used in early file systems and some
embedded systems.
Functions (8 points):
File Allocation: Contiguous allocation determines and manages the
allocation of contiguous blocks of storage space for files.
File Creation: When a new file is created, contiguous blocks of
storage are reserved to store the file's data.
File Reading: The starting location and length of a file's contiguous
block allow for efficient retrieval of file data.
File Writing: Contiguous allocation ensures that file data is written
to consecutive blocks for optimal performance.
File Deletion: When a file is deleted, the contiguous blocks it
occupied are marked as available for reuse.
File System Navigation: Contiguous allocation allows for easy
navigation within a file system since file blocks are stored
consecutively.
File Access Efficiency: Contiguous allocation can provide efficient
access to large files since the blocks are stored contiguously.
File System Optimization: Contiguous allocation simplifies the file
system implementation and can be efficient for certain workloads.
Advantages (5 points):
Simple Implementation: Contiguous allocation is straightforward to
implement compared to other allocation methods.
Sequential Access: It enables efficient sequential access of files,
especially when accessing large files.
Minimal Fragmentation: Since files are stored contiguously, there is
minimal fragmentation of storage space.
Low Overhead: The allocation table or data structure used in
contiguous allocation has low overhead, resulting in efficient file
system operations.
Fast File Retrieval: With contiguous allocation, file retrieval can be
faster compared to other allocation methods since there is no need to
traverse multiple non-contiguous blocks.
Disadvantages (5 points):
External Fragmentation: Contiguous allocation can lead to external
fragmentation as files are created and deleted, leaving gaps of
unused space that may not be efficiently utilized.
File Size Limitations: The contiguous nature of allocation may
impose limitations on the maximum file size, as large contiguous
blocks may not be available.
Poor Space Utilization: If the available free space is not contiguous,
it can lead to wasted space since it may not be usable for storing
files.
Limited Flexibility: Contiguous allocation makes it challenging to
insert or expand files dynamically, as it requires finding contiguous
free space.
Disk Defragmentation: Over time, as files are created and deleted,
the file system may become fragmented, requiring periodic disk
defragmentation to optimize storage utilization and performance.
Linked List Allocation
Definition (8 points):
Linked List Allocation is a file system implementation method that
uses a linked list data structure, known as the File Allocation Table
(FAT), to keep track of the storage blocks allocated to each file.
In this method, each file is divided into blocks of storage, and the
FAT maintains a chain of pointers that link these blocks together.
The FAT contains an entry for each storage block, indicating whether
it is allocated to a file or free.
The entries in the FAT store the addresses or pointers to the next
block in the file's chain, allowing for non-contiguous allocation of
storage space.
Linked List Allocation is commonly used in file systems like FAT16
and FAT32.
Functions (8 points):
File Allocation: Linked List Allocation uses the FAT to allocate and
manage storage blocks for files by updating the pointers in the
linked list.
File Creation: When a new file is created, the FAT allocates and
updates the linked list with the blocks required to store the file's
data.
File Reading: The FAT allows for efficient retrieval of file data by
following the linked list of blocks.
File Writing: Linked List Allocation enables efficient writing of file
data by appending new blocks and updating the pointers in the
linked list.
File Deletion: When a file is deleted, the FAT marks the
corresponding blocks as free, removing them from the linked list.
File System Navigation: Linked List Allocation allows for
navigation within the file system using the FAT to traverse the linked
lists associated with each file.
File Access Efficiency: Linked List Allocation can efficiently handle
files of varying sizes, as it allows non-contiguous allocation of
blocks.
File System Optimization: The use of linked lists in the FAT enables
flexibility in file allocation and storage management.
Advantages (5 points):
Efficient Space Utilization: Linked List Allocation minimizes
internal fragmentation, as it can allocate non-contiguous blocks,
utilizing storage space more efficiently.
Flexibility in File Size: This method allows for dynamic file size
changes, as files can be easily expanded by adding new blocks to the
linked list.
Simplified File Insertion and Deletion: Linked List Allocation
simplifies the process of inserting and deleting files, as it involves
updating the linked list pointers rather than shifting blocks.
Easy File System Maintenance: The use of the FAT in Linked List
Allocation makes file system maintenance tasks like file system
consistency checking and repair more manageable.
Support for Multiple File Systems: Linked List Allocation using FAT
is widely supported across various operating systems and platforms,
making it compatible and accessible.
Disadvantages (5 points):
Poor Sequential Access Performance: Retrieving data from a file
stored in non-contiguous blocks can result in slower sequential
access compared to contiguous allocation methods.
Increased Overhead: Linked List Allocation introduces additional
overhead in terms of storage space required for the FAT, which can
impact overall storage efficiency.
Limited Performance for Large Files: As the file size grows, the
overhead of traversing the linked list increases, leading to potential
performance degradation.
Fragmentation Over Time: Linked List Allocation can suffer from
external fragmentation as files are created, modified, and deleted,
leading to scattered free blocks within the storage space.
Complex File System Recovery: In case of FAT corruption or
failure, recovering the file system and reconstructing the linked lists
can be complex and time-consuming.
I/O device management
I/O device management in an operating system involves
recognizing and initializing connected devices, ensuring they are
ready for communication with the system.
It facilitates data transfer between I/O devices and the rest of the
system, handling synchronization, buffering, and error handling to
maintain data integrity.
The operating system handles interrupts generated by devices,
suspending and resuming programs to service the interrupt requests
and coordinate device activities.
Classification of I/O Devices:
Machine Readable or Block Devices:
Definition: Machine-readable or block devices are I/O devices that
read or write data in fixed-sized blocks or chunks.
Characteristics: a. They operate at the block level and access data in
fixed-sized blocks. b. Examples include hard disk drives (HDDs),
solid-state drives (SSDs), and USB flash drives. c. They provide
high-speed data transfer rates and are typically used for storage
purposes. d. Accessing data from block devices usually involves
seeking and reading or writing entire blocks at once. e. These
devices are often managed by the operating system's file system.
User Readable or Character Devices:
Definition: User-readable or character devices are I/O devices that
read or write data character by character.
Characteristics: a. They operate at the character level and handle
data one character at a time. b. Examples include keyboards, mice,
joysticks, and barcode scanners. c. They provide a way for users to
input or output data interactively. d. The operating system usually
processes each character as it arrives or is sent to the device. e.
These devices often require device drivers to translate user input or
output into a format that the operating system can understand.
Communication Devices:
Definition: Communication devices facilitate the transmission of
data between different systems or devices.
Characteristics: a. They enable communication between computers
or other devices over various communication channels. b. Examples
include network interface cards (NICs), modems, and wireless
adapters. c. They provide connectivity options such as Ethernet, Wi-
Fi, Bluetooth, or cellular networks. d. Communication devices allow
for data exchange and networking capabilities. e. They are often
managed by the operating system's network stack and require
appropriate drivers to function.
Controllers
Device drivers are software modules that can be plugged into an OS
to handle a particular device. Operating
System takes help from device drivers to handle all I/O devices.
The Device Controller works like an interface between a device and
a device driver. I/O units (Keyboard,
mouse, printer, etc.) typically consist of a mechanical component
and an electronic component where
electronic component is called the device controller.
There is always a device controller and a device driver for each
device to communicate with the Operating
Systems. A device controller may be able to handle multiple devices.
As an interface its main task is to
convert serial bit stream to block of bytes, perform error correction
as necessary.
Any device connected to the computer is connected by a plug and
socket, and the socket is connected to a
device controller. Following is a model for connecting the CPU,
memory, controllers, and I/O devices where
CPU and device controllers all use a common bus for
communication.
Memory-Mapped I/O I/O Mapped I/O
I/O devices have
I/O devices accessed
Addressing separate addresses
through memory addresses.
distinct from memory.
I/O devices share the same I/O devices have a
Address Range address space as the main distinct address space
memory. from memory.
Memory controller decodes
Address Separate I/O controller
memory addresses for I/O
Decoding decodes I/O addresses.
operations.
Dedicated IN and
Load and store instructions
Instructions OUT instructions used
used to access I/O devices.
for I/O access.
Utilizes the same bus for Requires separate bus
Bus Utilization both memory and I/O lines for I/O
operations. operations.
I/O devices accessed as if I/O devices have
Device
they were memory dedicated ports for
Interaction
locations. data transfer.
Interrupts can be handled Interrupt handling
Interrupt
using memory-mapped typically requires I/O
Handling
interrupt vectors. ports.
Address conflicts may occur
Separate address space
Address if I/O devices use
reduces the chance of
Conflicts overlapping memory
conflicts.
addresses.
Offers flexibility in using Provides dedicated
Flexibility memory instructions for I/O instructions for I/O
operations. operations.
Compatibility May be compatible with May be compatible with
with Legacy legacy systems that use legacy systems that use
Systems memory-mapped I/O. I/O-mapped I/O.
interrupt I/O Polled I/O
Handling CPU continuously
I/O device interrupts the CPU
Mechanis checks the status of I/O
when it requires attention.
m devices.
CPU can perform other tasks CPU is actively involved
CPU
while waiting for I/O in checking I/O device
Utilization
completion. status.
Response time depends
Responsive Provides faster responsiveness
on the polling frequency
ness as CPU can handle other tasks.
of the CPU.
Lower CPU overhead as the
Higher CPU overhead
Overhead CPU is not continuously
due to constant polling.
checking device status.
Higher throughput as CPU can Lower throughput as
Throughpu
perform other tasks CPU is dedicated to
t
concurrently. polling.
Device and CPU are Device and CPU
Synchroniz
synchronized through synchronization is not as
ation
interrupts. direct.
Requires interrupt handling Simpler to implement as
Complexit
mechanisms in hardware and no interrupt handling is
y
software. needed.
Lower latency as the CPU can Higher latency as the
Latency respond immediately to device CPU must wait for the
events. polling interval.
Well-suited for handling May become less
Scalability multiple I/O devices efficient with multiple
simultaneously. I/O devices.
Provides flexibility for Limited flexibility in
Flexibility handling diverse I/O device handling complex I/O
operations. operations.
DMA (Direct Memory Access)
Direct memory access (DMA) is a method that allows an
input/output (I/O) device to send or receive data
directly to or from the main memory, bypassing the CPU to speed up
memory operations.
The process is managed by a chip known as a DMA controller
(DMAC).

L
Goals of I/O Software:
Uniform Naming:
Provide a consistent and abstracted naming system for I/O devices,
allowing users to access them without being aware of the underlying
hardware names.
Enable easy interchangeability of devices without modifying
application code.
Synchronous versus Asynchronous:
Support both synchronous and asynchronous I/O operations to
accommodate different requirements.
Asynchronous operations allow the CPU to continue processing
other tasks while waiting for I/O completion.
Provide interrupt-driven mechanisms to handle asynchronous I/O
and manage blocking states efficiently.
Device Independence:
Achieve device independence by providing a common interface that
allows programs to access various I/O devices.
Allow programs to interact with different devices without rewriting
the code for each specific device.
Enable portability and ease of use by abstracting hardware-specific
details from application code.
Buffering:
Implement buffering mechanisms to manage data transfer between
devices and memory efficiently.
Break data into smaller groups and transfer it to buffers for
examination and processing.
Optimize I/O performance by balancing the rate of data filling and
emptying from buffers.
Error Handling:
Incorporate error handling mechanisms to detect and handle errors
generated by I/O devices.
Allow lower-level components, such as controllers, to handle errors
and prevent them from reaching higher levels.
Provide robust error reporting and recovery strategies to ensure
reliable I/O operations.
Shareable and Non-Shareable Devices:
Support both shareable and non-shareable devices in the I/O
software.
Enable multiple processes to share devices like hard disks, while
ensuring exclusive access to non-shareable devices like printers.
Implement resource allocation and scheduling mechanisms to
manage device sharing efficiently.
Handling I/O Methods:
Programmed I/O:
Data transfer controlled by the CPU.
Continuously checks I/O devices for inputs.
Carries out I/O requests until no further input signal is received.
Examples: Printing a document where the request is sent through the
CPU to the printer.
Interrupt-Based I/O:
Data transfer activity controlled by interrupts.
CPU can continue processing other tasks until an input signal from
an I/O device is received.
Interrupts the CPU to handle the I/O request.
Example: Keyboard strokes generating an interrupt signal to the
CPU to process the keystroke.
Direct Memory Access (DMA) I/O:
Direct transfer of data between memory and I/O devices.
Data transfer occurs without CPU involvement, reducing CPU
overhead.DMA controller manages the transfer between memory
and I/O devices.
Example: Transferring pictures from a camera plugged into a USB
port, where the DMA handles the transfer instead of the CPU.
IO Software Layers
Basically, input/output software organized in the following four
layers:
 Interrupt handlers
 Device drivers
 Device-independent input/output software
 User-space input/output software

In every input/output software, each of the above given four layer


has a well-defined function to perform
and a well-defined interface to the adjacent layers.
Interrupt Handlers
Whenever the interrupt occurs, then the interrupt procedure does
whatever it has to in order to handle the
interrupt.
Device Drivers
Basically, device drivers is a device-specific code just for controlling
the input/output device that are
attached to the computer system.
Disk Structure:
A modern hard disk consists of one or more surfaces, each
containing multiple tracks.Each track is divided into sectors, which
are the unit of information transfer.There is one read/write head for
each surface of the disk.The same track on all surfaces is referred to
as a cylinder, and the heads move in and out of the disk together.The
position of the read/write heads is commonly described using the
concept of cylinders, tracks, and surfaces.The sector is the
fundamental unit of data transfer, though whole tracks can also be
read or written depending on the hardware.File systems typically
focus on sectors and often refer to disk storage as a "block device."A
block typically corresponds to a sector, but it can also be a collection
of several sectors forming a logical block.

Disk Scheduling
Disk scheduling is done by operating systems to schedule I/O
requests arriving for the disk. Disk schedulingis also known as I/O
scheduling.Disk scheduling is important because:
 Multiple I/O requests may arrive by different processes and only
one I/O request can be served at a
time by the disk controller. Thus other I/O requests need to wait in
the waiting queue and need to be scheduled.
 Two or more request may be far from each other so can result in
greater disk arm movement.
 Hard drives are one of the slowest parts of the computer system
and thus need to be accessed in an
efficient manner
FCFS
FCFS is the simplest of all the Disk Scheduling Algorithms. In
FCFS, the requests are addressed in the orderthey arrive in the disk
queue. Let us understand this with the help of an example.
Example:
Suppose the order of request is- (82, 170, 43, 140, 24, 16, 190)
And current position of Read/Write head is: 50

So, total seek time:=(82-50)+(170-82)+(170-43)+(140-43)+(140-


24)+(24-16)+(190-16)=642
Advantages:
 Every request gets a fair chance
 No indefinite postponement
Disadvantages:
 Does not try to optimize seek time
 May not provide the best possible service
SSTF
In SSTF (Shortest Seek Time First), requests having shortest seek
time are executed first. So, the seek time of every request is
calculated in advance in the queue and then they are scheduled
according to their calculated seek time. As a result, the request near
the disk arm will get executed first. SSTF is certainly an
improvement over FCFS as it decreases the average response time
and increases the throughput of system. Let us understand this with
the help of an example.
Example:
Suppose the order of request is- (82, 170, 43, 140, 24, 16, 190)
And current position of Read/Write head is: 50

So, total seek time:


=(50-43)+(43-24)+(24-16)+(82-16)+(140-82)+(170-40)+(190-170)
=208
Advantages:
 Average Response Time decreases
 Throughput increases
Disadvantages:
 Overhead to calculate seek time in advance
 Can cause Starvation for a request if it has higher seek time as
compared to incoming requests
 High variance of response time as SSTF favors only some
requests
SCAN
In SCAN algorithm the disk arm moves into a particular direction
and services the requests coming in its path and after reaching the
end of disk, it reverses its direction and again services the request
arriving in its path. So, this algorithm works as an elevator and
hence also known as elevator algorithm. As a result, the requests at
the midrange are serviced more and those arriving behind the disk
arm will have to wait. Example:Suppose the requests to be addressed
are-82, 170, 43, 140, 24, 16, and 190. And the Read/Write arm is at
50, and it is also given that the disk arm should move “towards the
larger value”.

Therefore, the seek time is calculated as:


= (199-50) + (199-16)
=332
Advantages:
 High throughput
 Low variance of response time
 Average response time
Disadvantages:
 Long waiting time for requests for locations just visited by disk
arm

You might also like