Operating Systems – University Level – Pak Notes Hub
⚙ University Level — BS CS / BS IT

Operating Systems
Complete Notes

Processes · Memory Management · File Systems · Scheduling · Synchronization · All in Easy English

Process Management
Memory Hierarchy
Deadlocks
Unit 1

Operating Systems Basics

Introduction to OS Concepts and Functions

What is an Operating System?

An Operating System (OS) is system software that manages hardware resources and provides services to applications. It acts as an intermediary between users and hardware.

Main Functions of OS

  • Resource Management: CPU, Memory, Disk, I/O devices
  • Process Management: Create, schedule, terminate processes
  • Memory Management: Allocate and manage RAM
  • File Management: Organize and manage files
  • Security: Protect system from unauthorized access
  • User Interface: Command-line or graphical interface

Types of Operating Systems

TypeCharacteristicsExamples
Batch OSJobs processed in batches, no user interactionOlder mainframe systems
Time-Sharing OSMultiple users share system resourcesUNIX, Linux
Real-Time OSGuaranteed response timeAircraft control, medical devices
Distributed OSMultiple computers networked togetherNetwork systems
Embedded OSSpecialized for specific hardwareAndroid, iOS, Windows Embedded

OS Architecture

User Applications
        ↓
System Call Interface
        ↓
Kernel (Core of OS)
  - Process Management
  - Memory Management
  - File Management
  - I/O Management
        ↓
Hardware (CPU, Memory, Disk, I/O)
✏️ Practice: List 3 functions of OS and give real-world examples
Unit 2

Process Management

Creating, Scheduling, and Terminating Processes

Process Basics

A process is an instance of a program in execution. Each process has its own memory space and resources.

Process vs Program

ProgramProcess
Static code on diskDynamic execution in memory
One program, one copyOne program, multiple processes possible
No resources allocatedHas CPU time, memory, I/O resources

Process States

New → Ready → Running → Waiting → Terminated
  ↑_________________________↓
     (Context Switch)

States:
- New: Process created
- Ready: Waiting for CPU
- Running: Currently executing
- Waiting: Waiting for I/O or event
- Terminated: Execution complete

Process Control Block (PCB)

Data structure that stores information about a process:

  • PID: Process Identifier
  • Program Counter: Next instruction address
  • Registers: Saved register values
  • Memory: Base and limit registers
  • I/O Status: Open files, devices
  • Priority: Scheduling priority

Context Switching

Context switching is saving one process's state and loading another's. Overhead but necessary for multitasking.

💡 Each context switch saves PCB and updates hardware registers. More switches = more overhead!
✏️ Practice: Draw process state diagram and explain each transition
Unit 3

CPU Scheduling

Algorithms for Deciding Which Process Gets CPU Time

Scheduling Goals

  • Maximize CPU Utilization - Keep CPU busy
  • Maximize Throughput - Complete more processes
  • Minimize Turnaround Time - Reduce total execution time
  • Minimize Waiting Time - Reduce time in ready queue
  • Minimize Response Time - Quick first response

Scheduling Algorithms

AlgorithmDescriptionPros/Cons
FCFSFirst Come First ServedSimple but can have long waits
SJFShortest Job FirstOptimal but hard to predict
Round RobinFixed time slice per processFair but overhead
PriorityHigher priority firstStarvation possible
Multi-level QueueDifferent queues per priorityMore complex

FCFS Example

Processes: P1(24), P2(3), P3(3)  (Burst time in ms)

Timeline:
P1: 0 -------- 24
P2:           24 -- 27
P3:              27 -- 30

Waiting Times:
P1: 0, P2: 24, P3: 27
Average: 17ms
✏️ Practice: Compare FCFS vs SJF for the same processes
Unit 4

Process Synchronization

Coordinating Concurrent Processes

Critical Section Problem

When multiple processes access shared data, race conditions occur. Critical section is code accessing shared data that must execute atomically.

Solution Requirements

  • Mutual Exclusion: Only one process in critical section
  • Progress: Processes can't be blocked indefinitely
  • Bounded Waiting: Limited waits before entering

Synchronization Tools

ToolDescription
SemaphoreInteger with wait() and signal() operations
MutexBinary semaphore - locked or unlocked
MonitorHigh-level construct with entry procedure
LockSimple mechanism - acquire/release

Semaphore Example

Semaphore S = 1;  // Binary semaphore

Process P1:          Process P2:
wait(S);             wait(S);
// Critical Section  // Critical Section
signal(S);           signal(S);

Only ONE process enters at a time!
💡 Race Condition: Two processes accessing shared data simultaneously. Result depends on timing - unpredictable!
✏️ Practice: Explain producer-consumer problem and its solution
Unit 5

Deadlocks

When Processes Get Stuck Waiting for Each Other

Deadlock Definition

A deadlock is a situation where a process waits indefinitely for a resource held by another waiting process. Results in system hang.

Conditions for Deadlock (All 4 must exist)

  • Mutual Exclusion: Resources can't be shared
  • Hold and Wait: Processes hold resources while waiting
  • No Preemption: Resources can't be forcibly taken
  • Circular Wait: Circular chain of processes

Deadlock Handling Strategies

StrategyApproachCost
PreventionBreak one of 4 conditionsLow concurrency
AvoidanceBanker's algorithm - grant safelyOverhead
DetectionDetect deadlock, then recoverFrequent checks
IgnorancePretend deadlocks don't happenManual restart

Deadlock Detection

Wait-for graph: Node = process, edge = wait relationship. Cycle = deadlock.

✏️ Practice: Draw wait-for graph showing deadlock scenario
Unit 6

Memory Management

Allocating and Managing RAM

Memory Hierarchy

LevelSpeedSizeCost
RegistersFastestBytesHighest
L1 CacheVery FastKBVery High
L2 CacheFastMBHigh
RAMMediumGBLow
DiskSlowTBLowest

Memory Allocation Strategies

  • Contiguous: Entire process in continuous memory
  • Paging: Fixed-size pages, can be non-contiguous
  • Segmentation: Variable-size segments

Paging

Divide memory into fixed-size pages (typically 4KB). Process doesn't need contiguous space.

Logical Address: Page Number | Offset
Physical Address: Frame Number | Offset

Example: 4KB pages
Logical address 8000 → Page 1 (8000/4096) + Offset (8000%4096)
💡 TLB (Translation Lookaside Buffer): Cache for page table. Speeds up address translation!
✏️ Practice: Calculate page number and offset for given logical address
Unit 7

Virtual Memory

Extending Physical Memory Using Disk

Virtual Memory Concept

Virtual memory allows processes to use more memory than physically available. Unused pages stored on disk.

Demand Paging

Load pages only when needed, not all at once.

  • Page Hit: Page in memory, fast access
  • Page Fault: Page on disk, slow access, must load

Page Replacement Algorithms

AlgorithmHow It WorksPerformance
FIFOReplace oldest page firstPoor - Belady's anomaly
LRUReplace least recently usedGood - approximates optimal
OptimalReplace page used furthest in futurePerfect but impractical
ClockCircular queue with use bitGood - practical

Working Set

Set of pages actively used by process. OS tries to keep working set in memory to minimize faults.

✏️ Practice: Compare page faults for FIFO vs LRU with example
Unit 8

File Systems

Organizing and Managing Data on Disk

File System Basics

File system organizes data into files and directories. Manages storage space and retrieval.

File Attributes

  • Name: Human-readable identifier
  • Type: Extension (.txt, .exe, etc.)
  • Size: Number of bytes
  • Permissions: Read, write, execute
  • Timestamps: Creation, modification, access time
  • Owner: User who created file

File Organization

MethodStructureBest For
ContiguousSequential blocksFixed-size files
LinkedBlocks linked with pointersVariable-size files
IndexedIndex table pointing to blocksRandom access

Directory Structure

  • Single-level: All files in one directory
  • Two-level: Users have personal directories
  • Tree-structured: Hierarchical directories
✏️ Practice: Explain inode structure in UNIX file system
Unit 9

I/O Management

Input/Output Operations and Device Management

I/O Organization

User Program (I/O Request)
         ↓
I/O Manager / Device Driver
         ↓
I/O Controller / Hardware
         ↓
Physical Device (Disk, Printer, etc.)

I/O Techniques

TechniqueHow It WorksSpeedCPU Usage
PollingCPU repeatedly checks device statusSlowHigh (Wasteful)
InterruptDevice signals CPU when readyFastLow
DMADevice transfers data directly to memoryVery FastNone

Disk Scheduling Algorithms

AlgorithmStrategySeek Time
FCFSService in arrival orderLong
SSTFShortest seek time firstShort
SCANElevator - sweep back and forthGood
C-SCANOne-way sweep, return to startFair
💡 DMA (Direct Memory Access): Devices communicate directly with memory without CPU involvement. Much faster!
✏️ Practice: Calculate total seek time for disk requests using different algorithms
Unit 10

Security & Protection

Securing System and Data

Security Goals

  • Confidentiality: Keep data private
  • Integrity: Prevent unauthorized changes
  • Availability: System accessible when needed

User Authentication

  • Password: Something you know
  • Biometric: Something you are
  • Physical Token: Something you have

Access Control

  • DAC (Discretionary): Owner controls permissions
  • MAC (Mandatory): System enforces security policy
  • RBAC (Role-based): Permissions based on role

File Permissions (Unix)

rwxrwxrwx
├─ Owner (User)
├─ Group
└─ Others

r = read (4)
w = write (2)
x = execute (1)

Example: 755 = rwxr-xr-x
Owner: read+write+execute (7)
Group: read+execute (5)
Others: read+execute (5)
✏️ Practice: Convert permission codes and explain security implications

🎉 Congratulations!

You've completed the Operating Systems course! Master these concepts and ace your exams!

📚 Pak Notes Hub — Operating Systems Complete Notes | University Level | BS CS / BS IT
For corrections and suggestions: support@paknoteshub.com