Operating System
UNIT 1: Introduction to Operating System
What is Operating System?
An Operating System (OS) is system software that acts as an interface between user and
hardware. It manages system resources and provides a user-friendly environment to execute
applications.
Key Functions of Operating System:
Process management: Handles creation, scheduling and termination of processes.
Memory management: Allocates and deallocates memory to programs.
File system management: Controls how data is stored and retrieved.
Device management: Manages input/output devices through drivers.
Security and protection: Prevents unauthorized access to data and resources.
User interface: Provides command-line or graphical UI for interaction.
Types of Operating Systems:
1. Batch Operating System:
Users submit jobs in batch with no interaction.
OS processes batches one after another.
Example: Payroll systems.
Advantages:
Handles large repetitive jobs.
Reduces idle time.
Disadvantages:
Debugging is difficult.
Delayed output.
2. Time-Sharing Operating System:
Many users share the system using time slices.
Example: UNIX.
Advantages:
Quick response to users.
Efficient resource sharing.
Disadvantages:
Less reliability.
Complex implementation.
3. Multiprocessing Operating System:
Uses multiple CPUs for processing.
Tasks are divided across processors.
Advantages:
High performance.
Parallel execution.
Disadvantages:
Expensive hardware.
Complex software.
4. Real-Time Operating System (RTOS):
Responds quickly to inputs.
Used in medical systems, robotics.
Types:
Hard RTOS: Guarantees deadlines.
Soft RTOS: Tries to meet deadlines.
5. Distributed Operating System:
Collection of independent computers appears as one.
Enables resource sharing and remote access.
Advantages:
Load balancing.
Fault tolerance.
6. Network Operating System:
Controls servers and connected devices.
Example: Windows Server, UNIX.
System Components of Operating System:
Process management
Memory management
File system
I/O system
Secondary storage
Protection and security
Diagram: (Computer System ↔ OS ↔ User)
Summary:
Operating System is essential for any computer system. It acts as a resource manager, ensures
secure and efficient execution of user tasks.
UNIT 2: Process and Scheduling
What is a Process?
A process is a program in execution. It contains program code and current activity. It needs CPU
time, memory, files, and I/O devices.
Process Memory Layout:
Text: Contains program code.
Data: Stores global/static variables.
Heap: For dynamic memory allocation.
Stack: For function calls and local variables.
Process States:
1. New – process is being created
2. Ready – waiting to be assigned to processor
3. Running – process instructions being executed
4. Waiting – waiting for some event to occur
5. Terminated – finished execution
Process Control Block (PCB):
A data structure used by OS to store information about a process.
Includes: PID, Process State, Program Counter, Registers, Memory Limits, I/O status
CPU Scheduling:
CPU scheduling is the process of determining which process in the ready queue will be assigned
to CPU.
Scheduling Criteria:
CPU Utilization
Throughput
Turnaround Time
Waiting Time
Response Time
Types of Scheduling Algorithms:
1. First Come First Serve (FCFS):
o Non-preemptive
o Processes are attended in order they arrive
2. Shortest Job First (SJF):
o Non-preemptive
o Process with smallest burst time runs first
3. Shortest Remaining Time First (SRTF):
o Preemptive version of SJF
o Process with smallest remaining time is selected
4. Priority Scheduling:
o Each process is assigned a priority
o Highest priority process executes first
5. Round Robin:
o Each process gets a fixed time slot (quantum)
o After time expires, next process is scheduled
6. Multilevel Queue:
o Ready queue divided into multiple queues
o Each queue has its own scheduling algorithm
Multiprocessor Scheduling:
Used in systems with multiple processors
Types:
a. Asymmetric multiprocessing: One processor handles all scheduling
b. Symmetric multiprocessing: Each processor schedules its own processes
Advantages:
Increases performance
Provides parallelism
Conclusion:
Process and scheduling management are core to multitasking OS. Efficient scheduling improves
system responsiveness and performance.
Q3: Explain Process States with Diagram.
A process in an operating system can be in different states during its life cycle. These states
define the current activity of a process and how the operating system should manage it.
🔄 Different Process States:
1. New:
The process is being created.
2. Ready:
The process is waiting to be assigned to a processor.
1. Running:
The process is currently being executed by the CPU.
2. Waiting (Blocked):
The process is waiting for some I/O operation to complete.
3. Terminated:
The process has finished execution.
🔁 State Transitions:
Admit: New → Ready
Dispatch: Ready → Running
Timeout: Running → Ready
I/O Request: Running → Waiting
I/O Completion: Waiting → Ready
Exit: Running → Terminated
🧩 Process State Diagram:
+------+
| New |
+------+
Admit
+------+
|Ready |
+------+
Dispatch
+--------+
|Running |
+--------+
/ \
I/O Request / \ Exit
↓ ↓
+--------+ +-----------+
|Waiting | |Terminated |
+--------+ +-----------+
I/O Completion
+------+
|Ready |
+------+
Q4: What is PCB?
PCB stands for Process Control Block. It is a data structure maintained by the operating system
for every process. It contains all the information about a specific process.
📂 Information stored in PCB:
1. Process ID (PID):
Unique identifier for the process.
2. Process State:
Current status (New, Ready, Running, etc.)
3. Program Counter:
Address of the next instruction to execute.
4. CPU Registers:
Contents of all processor registers for the process.
5. Memory Management Information:
Page tables, memory limits, etc.
6. I/O Status Information:
List of I/O devices assigned, I/O operations pending.
📘 UNIT 1: Introduction to Operating
Systems
🔹1.1 What is an Operating System?
An Operating System (OS) is system software that acts as an interface between the user and
computer hardware. It manages all hardware and software resources of the system.
➤ Definitions:
An operating system is software that manages hardware, software, and system resources.
It provides a user-friendly interface and supports the execution of application programs
➤ Diagram: Operating System as an Interface
+------------+ +----------------+
| User | - | Operating System |
+------------+ +----------------+
| Computer Hardware|
🔹1.2 Objectives of an Operating System
Resource Management: Efficiently manage CPU, memory, disk, I/O devices.
Convenience: Provides a user-friendly interface.
Efficiency: Maximizes hardware utilization.
Security & Protection: Controls unauthorized access.
🔹1.3 Functions of Operating System
Function Description
Manages processes (creation, scheduling,
Process Management
termination).
Memory Management Allocates and deallocates memory space.
File System
Controls data storage and retrieval.
Management
I/O Management Manages input and output devices.
Security & Protection Prevents unauthorized access.
Function Description
Detects and handles system and application
Error Handling
errors.
🔹1.4 Types of Operating Systems
1. Batch OS
No direct interaction with user.
Jobs are batched and executed in groups.
Example: Payroll system
2. Time-Sharing (Multitasking) OS
Allows multiple users to use CPU time alternately.
Example: UNIX, Multics
3. Real-Time OS
Responds to inputs immediately.
Used in robotics, air-traffic systems.
Types: Hard RTOS and Soft RTOS
🖥️4. Distributed OS
Manages a group of distinct computers and makes them appear as a
single computer.
Example: LOCUS
🖥️5. Network OS
Provides services to computers connected in a network.
Example: Windows Server, Linux
🖥️6. Multiprocessing OS
Supports two or more processors running simultaneously.
Used in high-performance systems.
1.5 System Components of Operating System
➤ Major Components:
1. Process Management
2. Main Memory Management
3. File System Management
4. I/O System Management
5. Secondary Storage Management
6. Protection and Security
🔹1.6 Services Provided by OS
Program Execution
I/O Operations
File Manipulation
Communication
Error Detection
Resource Allocation
Security
✅ Summary of UNIT 1:
OS is essential for user-computer interaction.
It manages resources and provides services like memory, process, file, and device
management.
Different OS types serve different use-cases: real-time, time-sharing, distributed, etc.
📘 UNIT 2: Process Management
🔹2.1 What is a Process?
A process is a program in execution. It is
the basic unit of work in a system.
When a program is loaded into memory
and starts executing, it becomes a
process.
A process needs resources like CPU,
memory, I/O, etc.
🔹2.2 Process States
➤ A process moves through the following
states:
New – Process is being created.
Ready – Process is waiting to be assigned
to CPU.
Running – Instructions are being
executed.
Waiting (Blocked) – Waiting for some
event (I/O).
Terminated – Process has finished
execution. 🔁 Diagram: Process State
Transition
+-------+ Admit +-------+
Dispatch +---------+
| New | ----------------> | Ready |
---------------> | Running |
+-------+ +-------+
+---------+
↑ |
I/O Request |
|
↓ | ↓
+--------+ I/O Complete
+---------+
| Waiting| <-------------------- |
Terminate|
+--------+
+----------+
🔹2.3 Process Control Block (PCB)
The PCB is a data structure maintained by the OS to manage process information.
➤ Contents of PCB:
Process ID (PID)
Process state
Program counter
CPU registers
Memory management info
I/O status info
Accounting info
🔹2.4 Threads
A thread is the smallest unit of CPU execution within a process.
Multiple threads can exist in one process.
➤ Multithreading:
Allows concurrent execution within a process.
Improves application performance and resource usage.
🔹2.5 CPU Scheduling
CPU scheduling determines which process will use the CPU next.
➤ Scheduling Criteria:
CPU Utilization
Throughput
Turnaround Time
Waiting Time
Response Time
Fairness
🔹2.6 Scheduling Algorithms
1. First-Come First-Serve (FCFS):
Non-preemptive
Simple and easy
Process executed in order of arrival
2. Shortest Job First (SJF):
Non-preemptive or preemptive
Executes job with shortest burst time first
3. Priority Scheduling:
Assigns priority to each process
Higher priority executed first
4. Round Robin (RR):
Each process gets a small unit of CPU
time (time quantum)
Then it’s preempted and added to the
end of the queue
5. Multilevel Queue Scheduling:
Divides ready queue into several queues
based on priority or type
🔹2.7 Multiprocessing Scheduling
In Multiprocessor Systems, multiple CPUs
share the load.
Types:
Asymmetric multiprocessing: One
processor controls others.
Symmetric multiprocessing: All
processors are equal.
➤ Advantages:
Faster execution
Shared resources reduce cost
Fault tolerance (if one CPU fails)
🔹2.8 Real-Time Scheduling
Used in real-time systems where time
constraints are critical.
🔹2.9 Scheduler Types
Long-Term Scheduler: Controls job
admission
Short-Term Scheduler (CPU Scheduler):
Selects process for execution
Medium-Term Scheduler: Temporarily
removes process from memory
🔹2.10 Context Switching
When CPU switches from one process to
another, it:
Saves the current process state in its PCB
Loads the new process state from PCB
➤ Overhead involved during context
switching, but essential for multitasking.
✅ Summary of UNIT 2:
Processes go through various states.
OS uses PCB to manage each process.
CPU Scheduling algorithms decide
process execution.
Multithreading and multiprocessing
improve performance.
Real-time systems need strict timing.
📘 UNIT 3: Process Synchronization
🔹3.1 What is Process Synchronization?
Process Synchronization is a technique used to
ensure that multiple processes can operate
correctly when sharing resources like memory,
files, or devices.
It prevents conflicts when multiple processes
access shared resources concurrently.
Needed to avoid issues like race conditions,
inconsistent data, or deadlocks.
🔹3.2 Types of Processes
Independent Process:
Does not affect or get affected by other processes.
(e.g., process using its own private data)
Cooperating Process:
Affects or gets affected by other processes.
(e.g., processes sharing files or memory
🔹3.3 Race Condition
A Race Condition occurs when two or
more processes access shared data and
try to change it at the same time.
The outcome depends on the timing of
execution.
It leads to data inconsistency.
➡ Solution: Use synchronization methods
to avoid race conditions.
🔹3.4 Critical Section Problem
A Critical Section is a part of a program
that accesses shared resources.
➤ Structure:
Entry Section → Critical Section → Exit
Section → Remainder Section
Entry Section → Critical Section → Exit
Section → Remainder Section
➤ Three Conditions for Solution:
1. Mutual Exclusion – Only one process can enter critical
section at a time.
2. Progress – If no one is in the critical section, then a
decision must be made without delay.
3. Bounded Waiting – A limit must exist on how many times
other processes can enter their CS before a waiting process
gets its turn.
🔹3.5 Synchronization Hardware
Hardware solutions disable interrupts while accessing critical
sections, ensuring atomicity.
However, this is inefficient in multiprocessor systems.
🔹3.6 Software Synchronization: Mutex Locks
Mutex (Mutual Exclusion) locks are software tools.
Before entering a critical section, a process must acquire a
lock.
After finishing, it releases the lock.
Only one process can hold the lock at a time.
🔹3.7 Semaphores
A Semaphore is a variable used to control access to shared
resources.
➤ Two Atomic Operations:
Wait(P): Decrements the semaphore. Blocks if value < 0.
Signal(V): Increments the semaphore. Wakes up waiting
process.
➤ Types of Semaphores:
Binary Semaphore (Mutex): Values: 0 or 1
Counting Semaphore: Values ≥ 0 (used for multiple
resources)
🔹3.8 Classical Synchronization Problems
📌 1. Bounded Buffer (Producer-Consumer Problem)
Fixed-size buffer shared between a Producer and a Consumer.
Semaphores:
Mutex: For mutual exclusion
Empty: Count of empty slots
Full: Count of filled slots
📌 2. Dining Philosophers Problem
Five philosophers sit around a table with one fork between
each pair.
To eat, a philosopher must pick both left and right forks.
Problem leads to deadlock if all philosophers pick one fork.
➡ Solutions:
Limit number of philosophers eating.
Pick up both forks only if both are available.
📌 3. Readers-Writers Problem
Readers can read together, but only one writer can write at a
time.
If a writer is writing, readers and other writers must wait.
➡ Uses:
Semaphores and counters to manage reader and writer access.
🔹3.9 Monitors
High-level abstraction for synchronization.
Language-level support (e.g., Java’s synchronized keyword)
Only one process can execute inside a monitor at any time.
➤ Condition Variables:
Wait(): Process goes to waiting queue.
Signal(): Wakes one waiting process.
🔹3.10 Peterson’s Solution (for 2 Processes)
A software solution to the critical section problem:
Variables Used:
Flag[i]: Indicates process I wants to enter.
Turn: Indicates whose turn is next.
Satisfies:
Mutual Exclusion
Progress
Bounded Waiting
✅ Summary of UNIT 3:
Synchronization avoids conflicts in shared resources.
Race conditions and critical sections must be handled.
Semaphores, mutexes, monitors are key tools.
Classic problems like producer-consumer, dining
philosophers, and readers-writers explain synchronization
issues and solutions.
🟩 UNIT 3 Completed
📘 UNIT 4: Deadlocks
🔹4.1 What is a Deadlock?
A Deadlock is a situation where two or more processes are
waiting for resources that are being held by each other, and
thus none of them can proceed.
🔹4.2 Real-World Analogy
Imagine two people trying to cross a narrow bridge from
opposite sides. Both get stuck in the middle and neither can
move unless the other backs out — this is a deadlock.
🔹4.3 Conditions for Deadlock
Deadlock occurs only if all four conditions hold
simultaneously:
Mutual Exclusion:
Only one process can use a resource at a time.
Hold and Wait:
A process is holding one resource and waiting for another.
No Preemption:
Resources cannot be forcibly taken away
Circular Wait:
A cycle of waiting processes exists.
🔹4.4 Resource Allocation Graph (RAG)
Used to represent the allocation of resources to processes.
➤ Components:
Processes: Circles (P1, P2, …)
Resources: Squares (R1, R2, …)
Edges:
Request edge: → (Process → Resource)
Assignment edge: ← (Resource → Process)
🔁 Example: Resource Allocation Graph with Deadlock
P1 → R1 → P2 → R2 → P1 ← Circular wait
This forms a cycle, indicating a deadlock.
🔹4.5 Methods to Handle Deadlocks
There are three major methods:
1. Deadlock Prevention
Actively ensure that one of the four deadlock conditions is never true.
Mutual Exclusion: Make resources shareable.
🧮 Banker’s Algorithm
Used when multiple instances of each resource are available.
Available[] – Resources available
Max[][] – Max resources needed
Allocation[][] – Currently allocated resources
Need[][] = Max - Allocation
➡ The system checks for a safe sequence before granting any request.
3. Deadlock Detection and Recovery
Let deadlock occur, then detect and recover.
Use a Wait-For Graph (WFG)
Detect cycles in the graph.
➤ Recovery methods:
Kill one or more processes.
Preempt resources and restart processes.
4. Ignore the Problem (Ostrich Algorithm)
Assume deadlocks are rare.
Used in systems like UNIX.
🔹4.6 Deadlock vs Starvation
| Deadlock | Starvation |
| All processes are stuck | A process waits indefinitely |
| Caused by circular wait | Caused by unfair scheduling |
| Needs external recovery | Can be avoided using priorities |
✅ Summary of UNIT 4:
Deadlock occurs when processes are stuck waiting for each other.
Four necessary conditions: Mutual Exclusion, Hold and Wait, No Preemption, Circular
Wait.
Can be prevented, avoided, or detected.
Banker’s Algorithm ensures safe allocation.
Starvation is different but related to deadlock.
📘 UNIT 5: Memory Management
🔹5.1 Introduction to Memory Management
Memory management is a crucial function of the Operating
System that handles:
Allocation and deallocation of memory.
Tracking each byte in a computer’s memory.
Ensuring processes do not interfere with each other’s
memory.
Providing virtual memory when physical memory is
insufficient.
🔹5.2 Memory Management Tasks
The OS performs the following memory tasks:
Keep track of memory (used and free).
Allocate memory to processes.
Deallocate memory after process termination.
Manage swapping between main and secondary memory.
🔹5.3 Memory Allocation Techniques
➤ 1. Contiguous Memory Allocation
Entire process is stored in a single block of memory.
Two types:
o
o Fixed partitioning: Memory is divided into fixed-size blocks.
o Variable partitioning: Memory is allocated based on process size.
Problems:
External fragmentation
Inefficient memory use
➤ 2. Paging
Solves external fragmentation.
Logical memory divided into pages.
Physical memory divided into frames.
Each page is mapped to a frame using a page table.
➤ Diagram (Paging):
Logical Memory Physical Memory
| Page 0 | --------| Frame 5|
| Page 1 | --------| Frame 2|
| Page 2 | --------| Frame 1|
Advantages:
Eliminates external fragmentation
Efficient memory use
Disadvantages:
Overhead of maintaining page tables
Internal fragmentation in last page
➤ 3. Segmentation
Memory divided into logical segments like:
Code
Data
Stack
Each segment has:
Base: starting address
Limit: length
Advantages:
Logical division of memory
Supports modular programming
Disadvantages:
May lead to external fragmentation
🔹5.4 Virtual Memory
Virtual Memory allows execution of processes that are larger than physical memory.
Uses a combination of main memory + secondary storage.
Implemented using paging or segmentation.
Benefits:
More processes can run simultaneously.
Reduces need for large RAM.
Provides memory protection and isolation.
🔹5.5 Demand Paging
A technique where only required pages are loaded into memory.
If a page is not in memory, a page fault occurs.
The OS loads the missing page from disk.
Advantages:
Reduces memory usage
Loads only what is needed
Disadvantages:
High page fault rate if not managed properly
🔹5.6 Page Replacement Algorithms
Used when memory is full and a page needs to be removed:
Algorith
Description
m
FIFO Removes oldest loaded page first
LRU Removes page that was least recently used
Removes page that won’t be used for longest time
Optimal
(theoretical best)
5.7 Thrashing
A condition where too much paging reduces CPU performance.
System spends more time in swapping pages than executing processes.
Causes:
Too many processes
Not enough memory
Poor page replacement
Solution:
Reduce degree of multiprogramming
Increase memory allocation
5.9 Swapping
Temporarily moves processes from main memory to
secondary memory (disk) and back.
Used when memory is low or to balance CPU load.
Summary of UNIT 5:
Memory management ensures efficient and secure memory use.
Paging and segmentation solve fragmentation problems.
Virtual memory supports large programs using disk.
Page replacement is used when memory is full.
Thrashing is harmful and must be controlled.
📘 UNIT 6: File and I/O Management
🔹6.1 Introduction to File Management
A file is a collection of related information stored
on a disk.
The Operating System (OS) is responsible for
managing files and directories on storage devices.
➤ File System Responsibilities:
Creating and deleting files
Creating and managing directories
Mapping files to physical disk
File access control and security
File backup and recovery
🔹6.2 File Attributes
Each file has several attributes:
File name
File type (e.g., .txt, .exe)
Size
Location on disk
Creation and modification date
Access permissions
🔹6.3 File Operations
The OS provides system calls for file operations:
Create
Open
Read
Write
Append
Close
Delete
Rename
🔹6.4 File Access Methods
Different ways to access file contents:
Method Description
Sequential Read data in order, one by one (e.g.,
text files)
Direct Access any block using its address (e.g.,
database)
Indexed Use index to find data blocks (e.g., large
DBMS)
🔹6.5 Directory Structure
Directories are containers for files and
subdirectories.
➤ Types of Directory Structures:
Single-Level Directory:
All files in one directory — simple but no
organization.
Two-Level Directory:
Separate directory for each user.
Tree-Structured Directory:
Hierarchical — subdirectories within directories.
Acyclic Graph Directory:
Allows sharing of subdirectories or files.
General Graph Directory:
Directory may contain cycles — complex to
manage.
🔹6.6 File Allocation Methods
Defines how files are stored on disk:
Method Description
Contiguous Files stored in consecutive blocks.
Fast access but causes fragmentation.
Linked Each block points to the next. Slower,
but no fragmentation.
Indexed Uses index block with pointers to file
blocks. Efficient and flexible.
🔹6.7 Free Space Management
Tracks which disk blocks are free for use.
Methods:
Bit Map: 0 = free, 1 = used
Free List: Linked list of free blocks
Grouping: Store addresses of free blocks in each
free block
🔹6.8 Disk Scheduling Algorithms
Used to determine the order of servicing disk I/O
requests.
Algorithm Description
FCFS (First Come First Serve) Requests served
in order of arrival.
SSTF (Shortest Seek Time First) Nearest track
served first.
SCAN (Elevator) Head moves back and forth
servicing requests.
LOOK Similar to SCAN but only goes as far as
the last request.
🔹6.9 Introduction to I/O System
The I/O system handles communication between
CPU and peripheral devices like keyboard, mouse,
printer, etc.
➤ I/O Management Tasks:
Manage device communication
Buffering and caching
Error detection and recovery
Device drivers
🔹6.10 Types of I/O Communication
Type Description
Programmed I/O CPU waits for I/O to complete
Interrupt-Driven I/O Device interrupts CPU
when ready
DMA (Direct Memory Access) Device transfers
data directly to/from memory
🔹6.11 I/O Buffering
Buffering is temporary data storage in memory
during data transfer.
Single Buffering: One buffer at a time.
Double Buffering: Two buffers — one used while
the other fills.
Circular Buffering: Multiple buffers in a ring —
used for continuous input/output.
✅ Summary of UNIT 6:
File system organizes, stores, and secures data.
OS provides multiple access and allocation
methods.
Directory structures manage large file systems.
Disk scheduling improves performance.
I/O system handles device communication
efficiently using drivers, buffers, and DMA.
🟩 UNIT 6 Completed.
!
Is this conversation helpful so far?