0% found this document useful (0 votes)
3 views60 pages

Key Components of Operating Systems

The document provides comprehensive notes on operating systems, covering key components such as process management, memory management, and I/O system management. It includes definitions, functions, examples, and the importance of various operating system services and structures. Additionally, it discusses UNIX and Linux, their differences, and directory structures, along with detailed explanations of processes and their states.

Uploaded by

uk724379
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views60 pages

Key Components of Operating Systems

The document provides comprehensive notes on operating systems, covering key components such as process management, memory management, and I/O system management. It includes definitions, functions, examples, and the importance of various operating system services and structures. Additionally, it discusses UNIX and Linux, their differences, and directory structures, along with detailed explanations of processes and their states.

Uploaded by

uk724379
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Operating system Final NOTES by anees ahmad

Contents
🧠 Operating System Components..................................9
1 Process Management..............................................9
💡 Definition:...........................................................9
⚙️Functions:...........................................................9
🧩 Example:..............................................................9
🧠 Why It’s Important:.............................................9
2 Main Memory Management...................................9
💡 Definition:...........................................................9
⚙️Functions:...........................................................9
🧩 Example:..............................................................9
🧠 Why It’s Important:.............................................9
3 Secondary Storage Management..........................10
💡 Definition:.........................................................10
⚙️Functions:.........................................................10
🧩 Example:............................................................10
🧠 Why It’s Important:...........................................10
4 I/O System Management......................................10
💡 Definition:.........................................................10
⚙️Functions:.........................................................10
🧩 Example:............................................................10
🧠 Why It’s Important:...........................................10
5 Protection System.................................................11
💡 Definition:.........................................................11
⚙️Functions:.........................................................11
🧩 Example:............................................................11
🧠 Why It’s Important:...........................................11
6 Networking...........................................................11
💡 Definition:.........................................................11
⚙️Functions:.........................................................11
🧩 Example:............................................................11
🧠 Why It’s Important:...........................................11
7 Command Line Interpreter (CLI)...........................12

P a g e 1 | 60
Operating system Final NOTES by anees ahmad
💡 Definition:.........................................................12
⚙️Functions:.........................................................12
🧩 Example:............................................................12
🧠 Why It’s Important:...........................................12
🧾 Summary Table: OS Components..............................12
🧠 Operating System Services........................................12
1 Program Execution................................................13
💡 Definition:.........................................................13
⚙️How It Works:..................................................13
🧩 Example:............................................................13
🧠 Why It’s Important:...........................................13
🧩 Analogy:.............................................................13
2 I/O Operations.......................................................13
💡 Definition:.........................................................13
⚙️How It Works:..................................................13
🧩 Example:............................................................13
🧠 Why It’s Important:...........................................13
🧩 Analogy:.............................................................14
3 File System Manipulation.....................................14
💡 Definition:.........................................................14
⚙️How It Works:..................................................14
🧩 Example:............................................................14
🧠 Why It’s Important:...........................................14
🧩 Analogy:.............................................................14
4 Communication Services.......................................14
💡 Definition:.........................................................14
⚙️How It Works:..................................................14
🧩 Example:............................................................14
🧠 Why It’s Important:...........................................14
🧩 Analogy:.............................................................15
5 Error Detection......................................................15
💡 Definition:.........................................................15
⚙️How It Works:..................................................15

P a g e 2 | 60
Operating system Final NOTES by anees ahmad
🧩 Example:............................................................15
🧠 Why It’s Important:...........................................15
🧩 Analogy:.............................................................15
6 Resource Management.........................................15
💡 Definition:.........................................................15
⚙️How It Works:..................................................15
🧩 Example:............................................................15
🧠 Why It’s Important:...........................................15
🧩 Analogy:.............................................................16
7 Accounting.............................................................16
💡 Definition:.........................................................16
⚙️How It Works:..................................................16
🧩 Example:............................................................16
🧠 Why It’s Important:...........................................16
🧩 Analogy:.............................................................16
8 Protection..............................................................16
💡 Definition:.........................................................16
⚙️How It Works:..................................................16
🧩 Example:............................................................16
🧠 Why It’s Important:...........................................16
🧩 Analogy:.............................................................17
🧾 Summary Table: OS Services.....................................17
🧠 Operating System Kernel & System Calls..................17
1 What is the OS Kernel?..........................................17
💡 Definition:.........................................................17
⚙️Functions of the Kernel:...................................17
🧩 Example:............................................................18
🧩 2 What Are System Calls?......................................18
💡 Definition:.........................................................18
⚙️How It Works:..................................................18
🧩 Example:............................................................18
🧠 Why System Calls Are Important:......................18
🧩 3 Types of System Calls.........................................18

P a g e 3 | 60
Operating system Final NOTES by anees ahmad
1. Process Control System Calls............................18
💡 Definition:.........................................................18
⚙️Common Process Control Calls:.......................18
🧩 Example:............................................................19
🧩 Analogy:.............................................................19
2. File Management System Calls.........................19
💡 Definition:.........................................................19
⚙️Common File Management Calls:....................19
🧩 Example:............................................................19
🧩 Analogy:.............................................................19
3. Device Management System Calls....................19
💡 Definition:.........................................................19
⚙️Common Device Management Calls:...............19
🧩 Example:............................................................19
🧩 Analogy:.............................................................19
4. Information Maintenance System Calls............20
💡 Definition:.........................................................20
⚙️Common Information Maintenance Calls:.......20
🧩 Example:............................................................20
🧩 Analogy:.............................................................20
5. Communication System Calls............................20
💡 Definition:.........................................................20
⚙️Common Communication Calls:.......................20
🧩 Example:............................................................20
🧩 Analogy:.............................................................20
🧾 Summary Table: System Calls....................................20
🧠 System Call Execution & OS Structures.....................21
1 System Call Execution............................................21
💡 What is System Call Execution?.........................21
⚙️Steps of System Call Execution:........................21
🧩 Example:............................................................21
🧠 Why System Call Execution Is Important:..........21
🧩 Analogy:.............................................................22

P a g e 4 | 60
Operating system Final NOTES by anees ahmad
2 Semantics of System Call Execution......................22
💡 What is Semantics of System Call Execution?. . .22
⚙️Key Points of Semantics:..................................22
🧩 Example:............................................................22
🧠 Why Semantics Matter:.....................................22
🧩 Analogy:.............................................................22
3 OS Structures.........................................................22
💡 Key OS Structures:.............................................22
1️ Simple Structure (Monolithic Kernel)................23
💡 Definition:.........................................................23
⚙️Characteristics:.................................................23
🧩 Example:............................................................23
🧠 Why It’s Important:...........................................23
2️ Layered Approach.............................................23
💡 Definition:.........................................................23
⚙️Characteristics:.................................................23
🧩 Example:............................................................23
🧠 Why It’s Important:...........................................23
3️ Microkernel.......................................................23
💡 Definition:.........................................................23
⚙️Characteristics:.................................................24
🧩 Example:............................................................24
🧠 Why It’s Important:...........................................24
4️ Virtual Machines (VMs).....................................24
💡 Definition:.........................................................24
⚙️Characteristics:.................................................24
🧩 Example:............................................................24
🧠 Why It’s Important:...........................................24
🧾 Summary Table: OS Structures..................................24
Components of Operating System................................25
1. Introduction..........................................................25
2. Major Components of Operating System.............25
1. Kernel...............................................................25
2. Process Management.......................................25
P a g e 5 | 60
Operating system Final NOTES by anees ahmad
3. Memory Management......................................26
4. File Management..............................................26
5. Device Management.........................................26
6. User Interface (UI)............................................26
3. Diagram: Components of Operating System........27
4. Quick Summary Table...........................................27
System Design and Implementation (Operating System)27
Basic Idea (In Very Simple Words)............................27
Main Parts of System Design & Implementation......27
1. User......................................................................27
Definition..............................................................27
Simple Explanation...............................................28
Example................................................................28
2. System Administrator (Admin).............................28
Definition..............................................................28
Simple Explanation...............................................28
Example................................................................28
3. Mechanism...........................................................28
Definition..............................................................28
Simple Explanation...............................................28
Examples..............................................................28
4. Policy....................................................................29
Definition..............................................................29
Simple Explanation...............................................29
Examples..............................................................29
🔥 Mechanism vs Policy.............................................29
Best Analogy.........................................................29
5. Language (Implementation Language).................29
Definition..............................................................29
Simple Explanation...............................................29
Common Languages Used....................................29
How All These Fit Together (Big Picture)..................29
One-Line Summary...................................................30
Mnemonic to Remember Everything Easily 🧠..........30
P a g e 6 | 60
Operating system Final NOTES by anees ahmad
“U-S-M-P-L” → Use Smart Machines Properly Lovingly 😄 30
UNIX and Linux – Detailed Overview & Key Differences30
1. What is UNIX?.......................................................30
Definition..............................................................30
Simple Explanation...............................................30
Key Features of UNIX............................................30
Examples of UNIX Systems...................................30
2. What is Linux?......................................................30
Definition..............................................................30
Simple Explanation...............................................30
Key Features of Linux............................................30
Examples of Linux Distributions (Distros).............30
3. Relationship Between UNIX and Linux..................31
Very Important Concept.......................................31
Analogy.................................................................31
4. Key Differences Between UNIX and Linux (⭐ Most Important Part ⭐)31
Comparison Table (Write This in Exam 💯)............31
5. Architecture Similarity (UNIX & Linux)..................31
Explanation...........................................................31
6. Why Linux Became More Popular Than UNIX?.....31
Reasons (Bullet Points for Exams)........................31
7. Security Comparison.............................................32
8. Mnemonic to Remember Differences 🧠...............32
“UNIX is COSTLY & CLOSED, Linux is FREE & FLEXIBLE” 32
9. One-Line Summary...............................................32
Browsing Directory Structure of UNIX..........................32
1. What is UNIX Directory Structure?.......................32
Definition (Exam-ready)........................................32
Simple Explanation...............................................32
Analogy.................................................................32
2. Root Directory ( / )................................................32
Very Important Point............................................32
3. Important Directories in UNIX (Must Remember) 32
/bin (Binary)..........................................................32
P a g e 7 | 60
Operating system Final NOTES by anees ahmad
/sbin (System Binary)............................................33
/etc (Editable Text Configuration)........................33
/home...................................................................33
/root.....................................................................33
/usr (User System Resources)...............................33
/var (Variable files)...............................................34
/tmp (Temporary files).........................................34
/dev (Devices).......................................................34
/lib (Libraries).......................................................34
/proc (Process information)..................................34
4. Diagram of UNIX Directory Structure...................34
5. Commands Used to Browse Directory Structure. .35
1. pwd (Print Working Directory)..........................35
2. ls (List)...............................................................35
3. cd (Change Directory).......................................35
4. tree...................................................................35
5. find...................................................................35
6. du (Disk Usage).................................................35
7. stat....................................................................35
6. Important Comparison (Exam Alert 🚨).................36
/bin vs /sbin..........................................................36
7. Mnemonic to Remember Directories 🧠................36
“Be Safe Every Home User Visits The Dark Library Properly” 36
8. One-Line Exam Summary......................................36
PROCESS (IN DETAIL)....................................................36
1️What is a Process?..................................................36
✅ Definition...........................................................36
🔹 Simple Explanation............................................36
🔹 Program vs Process (Must-know comparison). .36
🔹 What Does a Process Contain? (VERY IMPORTANT) 37
🔹 Real-Life Analogy...............................................37
2️ CPU-Bound and I/O-Bound Processes...................37
🔹 CPU Burst & I/O Burst (KEY IDEA)..........................37
2️ A. CPU-Bound Process (IN DETAIL)........................37
P a g e 8 | 60
Operating system Final NOTES by anees ahmad
✅ Definition...........................................................37
🔹 Characteristics...................................................37
🔹 Examples...........................................................37
🔹 Analogy.............................................................37
🧠 Mnemonic.........................................................37
2️ B. I/O-Bound Process (IN DETAIL)..........................38
✅ Definition...........................................................38
🔹 Characteristics...................................................38
🔹 Examples...........................................................38
🔹 Analogy.............................................................38
🧠 Mnemonic.........................................................38
🔥 CPU-Bound vs I/O-Bound (EXAM TABLE)..............38
3️ Mechanism of Process Execution (VERY IMPORTANT) 38
🔹 Step-by-Step Mechanism of Process Execution....38
🟢 Step 1: Program Submission..............................38
🟢 Step 2: Process Creation....................................38
🟢 Step 3: Process Enters Ready State....................38
🟢 Step 4: CPU Allocation (Dispatch)......................39
🟢 Step 5: Execution Cycle......................................39
🟢 Step 6: Context Switching..................................39
🟢 Step 7: Process Termination..............................39
🔹 Process Execution Flow.........................................39
4 Why This Mechanism Is Important?.....................39
🧠 MASTER MNEMONICS (REVISION GOLD)..............39
🔹 Process Definition.............................................39
🔹 CPU vs I/O.........................................................39
✨ FINAL 2-LINE SUMMARY.......................................39
PROCESS STATES & PROCESS CONTROL BLOCK (PCB). .39
PROCESS STATES (IN DETAIL)....................................39
1️ Why Do We Need Process States?........................39
3️ Explanation of Each Process State (DETAILED)......40
🟢 1. NEW STATE....................................................40
🔹 Meaning............................................................40
🧠 Example.............................................................40
P a g e 9 | 60
Operating system Final NOTES by anees ahmad
📝 Exam Point........................................................40
🟡 2. READY STATE.....................................................40
🔹 Meaning............................................................40
🧠 Example.............................................................40
📝 Exam Point........................................................40
🔴 3. RUNNING STATE................................................40
🔹 Meaning............................................................40
🧠 Example.............................................................40
📝 Exam Point........................................................41
🔵 4. WAITING (BLOCKED) STATE...............................41
🔹 Meaning............................................................41
🧠 Example.............................................................41
📝 Exam Point........................................................41
⚫ 5. TERMINATED STATE.........................................41
🔹 Meaning............................................................41
🧠 Example.............................................................41
📝 Exam Point........................................................41
4️ Process State Transitions (VERY IMPORTANT)......41
5️ Process State Diagram (DESCRIBE IN EXAM).........41
🧠 Mnemonic for Process States................................41
PROCESS CONTROL BLOCK (PCB)..................................42
What is Process Control Block (PCB)?.......................42
✅ Definition...........................................................42
7 Why PCB is Needed?.............................................42
8 Information Stored in PCB (IN DETAIL).................42
🔹 1. Process Identification....................................42
🔹 2. Process State.................................................42
🔹 3. CPU Context Information..............................42
🔹 4. Scheduling Information.................................42
🔹 5. Memory Management Information..............42
🔹 6. I/O Status Information...................................42
🧠 PCB Content Mnemonic........................................42
9 PCB MECHANISM & COMPLETE WORKING (STEP-BY-STEP) 43
🔹 Step 1: Process Creation........................................43
P a g e 10 | 60
Operating system Final NOTES by anees ahmad
🔹 Step 2: Process Execution......................................43
🔹 Step 3: Context Switch Occurs..............................43
🔹 Step 4: Saving Process State..................................43
🔹 Step 5: Loading Next Process................................43
🔹 Step 6: Process Termination..................................43
🔁 PCB LIFE CYCLE......................................................43
🔥 Key Exam Difference: PCB vs Program..................43
🔚 FINAL SUMMARY...................................................43
PROCESS SCHEDULING QUEUES (IN DETAIL)................44
1 What is a Process Scheduling Queue?...................44
✅ Definition...........................................................44
🔹 Simple Explanation............................................44
2 Why Are Scheduling Queues Needed?.................44
3 Types of Process Scheduling Queues.....................44
4 JOB QUEUE (IN DETAIL).............................................44
✅ Definition...........................................................44
🔹 Key Characteristics............................................44
🔹 What Happens Here?........................................44
🔹 Analogy.............................................................45
5 READY QUEUE (IN DETAIL)....................................45
✅ Definition...........................................................45
🔹 Key Characteristics............................................45
🔹 What Happens Here?........................................45
🔹 Analogy.............................................................45
6 DEVICE QUEUE (IN DETAIL)....................................45
✅ Definition...........................................................45
🔹 Key Characteristics............................................45
🔹 Examples...........................................................45
🔹 Analogy.............................................................45
7 PROCESS MIGRATION BETWEEN QUEUES (VERY IMPORTANT) 46
🔄 Step-by-Step Process Migration............................46
🟢 Step 1: Job Submission......................................46
🟢 Step 2: Admission to Memory...........................46
🟢 Step 3: CPU Allocation.......................................46
P a g e 11 | 60
Operating system Final NOTES by anees ahmad
🟢 Step 4: I/O Request............................................46
🟢 Step 5: I/O Completion......................................46
🟢 Step 6: Process Termination..............................46
8 COMPLETE MECHANISM (HOW OS USES QUEUES)46
🔹 Mechanism of Process Scheduling Queues.......46
9 COMMON EXAM COMPARISON (VERY USEFUL)....47
1 MNEMONICS FOR QUICK REVISION 🧠...................47
🔹 Queues..............................................................47
🔹 Migration...........................................................47
🔚 FINAL SUMMARY..................................................47
SCHEDULING (IN OPERATING SYSTEM)........................47
1️ What is Scheduling?..............................................47
✅ Definition...........................................................47
🔹 Simple Explanation............................................47
🔹 Real-Life Analogy...............................................47
2️ Why Scheduling is Needed?..................................47
3️ Types of Scheduling (VERY IMPORTANT)..............48
4 LONG-TERM SCHEDULING (JOB SCHEDULER)...........48
✅ Definition...........................................................48
🔹 What It Controls................................................48
🔹 How It Works.....................................................48
🔹 Frequency..........................................................48
🔹 Example.............................................................48
🧠 Analogy..............................................................48
📌 Exam Tip............................................................48
5 SHORT-TERM SCHEDULING (CPU SCHEDULER)..........48
✅ Definition...........................................................49
🔹 What It Controls................................................49
🔹 How It Works.....................................................49
🔹 Frequency..........................................................49
🔹 Example.............................................................49
🧠 Analogy..............................................................49
📌 Exam Tip............................................................49
6 MEDIUM-TERM SCHEDULING (SWAPPER)................49
P a g e 12 | 60
Operating system Final NOTES by anees ahmad
✅ Definition...........................................................49
🔹 Key Concept: Swapping.....................................49
🔹 What It Controls................................................49
🔹 How It Works.....................................................49
🔹 Frequency..........................................................49
🧠 Analogy..............................................................50
📌 Exam Tip............................................................50
7 COMPARISON TABLE.................................................50
8 HOW ALL SCHEDULERS WORK TOGETHER (BIG PICTURE) 50
🧠 MASTER MNEMONIC (REVISION GOLD)................50
🔚 FINAL SUMMARY...................................................50
CONTEXT SWITCHING (OPERATING SYSTEMS).............50
1️ Definition..............................................................50
2️ Simple Explanation................................................51
🔹 Analogy.............................................................51
3 What Exactly Is Saved During Context Switch?......51
4 When Does Context Switching Occur?..................51
5 Step-by-Step Mechanism of Context Switching....51
🔹 Exam Diagram...................................................51
6 Why Context Switching Is Important.....................51
7 Disadvantages / Cost.............................................52
8 Analogy to Remember for Exam............................52
9 Mnemonic (For Quick Revision).............................52
🔚 Final Summary.......................................................52
FORK() IN OPERATING SYSTEMS...................................52
1 Definition...............................................................52
2 Key Points About Fork...........................................52
3 How Fork Works (Mechanism)..............................52
4 Example in C (Unix/Linux)......................................52
🔹 Explanation........................................................53
5 Important Notes About Fork.................................53
🔹 Copy-On-Write Optimization.............................53
6 Analogy (For Easy Memory)...................................53
7 Exam Tip................................................................53
P a g e 13 | 60
Operating system Final NOTES by anees ahmad
🔚 Final Summary......................................................53
THREADS IN OPERATING SYSTEMS...............................53
1 Definition...............................................................53
2 Key Points About Threads......................................54
🔹 Analogy (Easy to Remember)............................54
3 Advantages of Threads..........................................54
4 Types of Threads...................................................54
🔹 1. User-Level Threads (ULT)...............................54
🔹 2. Kernel-Level Threads (KLT)............................54
🔹 3. Hybrid Threading...........................................54
5 Thread Components (IN DETAIL)...........................54
6 Thread States.........................................................54
7 Thread vs Process (Exam Table)............................55
8 Thread Mechanism / Execution.............................55
🔹 Step 1: Thread Creation.....................................55
🔹 Step 2: Thread Scheduling.................................55
🔹 Step 3: Thread Execution...................................55
🔹 Step 4: Termination...........................................55
9 Real-Life Example..................................................55
🔟 Mnemonics for Quick Revision..............................55
🔚 Final Summary.......................................................55

🧠 Operating System
Components
An Operating System (OS) is made up of several
important components that manage different
hardware and software resources in the system.
The OS’s primary role is to ensure the efficient
operation of the computer system and provide an
interface for users to interact with the machine.

1 Process Management

💡 Definition:
P a g e 14 | 60
Operating system Final NOTES by anees ahmad
Process Management is the function of the OS ⚙️Functions:
responsible for managing processes in the system. A
process is simply a program in execution.  Memory allocation: Decides which
processes will be loaded into which areas of
⚙️Functions: memory.
 Memory deallocation: Frees memory once
 Creation and termination of processes: processes are done executing.
The OS manages when and how processes  Memory protection: Prevents one process
are started and stopped. from interfering with the memory space of
 Process scheduling: It decides the order in another.
which processes will run (CPU scheduling).  Virtual memory: Allows programs to use
 Process synchronization: Ensures that more memory than physically available by
processes coordinate their actions without swapping data between RAM and disk.
interfering with each other.
 Inter-process communication (IPC):
Allows processes to share data and
synchronize actions. 🧩 Example:

When you run a program, it gets loaded into RAM.


The OS ensures that there is enough space for it to
🧩 Example: run and that other programs’ data won’t interfere
with it. If RAM is full, virtual memory comes into
When you open multiple apps on your computer, play, using space from the hard drive.
each app is a separate process. The OS manages the
CPU time and memory allocation for each app so
they can run efficiently.
🧠 Why It’s Important:

 Optimizes system performance by


🧠 Why It’s Important: efficiently using available RAM.
 Prevents crashes by isolating memory
 Ensures multitasking: Processes can run spaces of processes.
concurrently.  Enables larger programs to run by utilizing
 Guarantees fair resource allocation (CPU virtual memory.
time).
 Maintains process isolation: One process
cannot corrupt another.
3 Secondary Storage Management

💡 Definition:
2 Main Memory Management
Secondary storage refers to non-volatile memory
💡 Definition: like hard drives, SSDs, and external storage
devices. The OS is responsible for managing this
Main memory management involves managing permanent storage.
RAM (Random Access Memory), where programs
and data are stored temporarily during execution.
P a g e 15 | 60
Operating system Final NOTES by anees ahmad
⚙️Functions:  Buffering: The OS stores data temporarily
in memory buffers before sending it to an
 File system management: The OS manages I/O device or from an I/O device.
the organization and storage of files on  Spooling: It queues I/O tasks to be executed
secondary storage. later, which prevents a device from being
 Disk scheduling: Controls the order in overloaded.
which disk requests are processed.
 Data retrieval: Ensures fast and efficient
reading and writing of data from storage
devices. 🧩 Example:
 Backup and recovery: Provides
mechanisms to recover data in case of When you print a document, the OS manages how
failure. the document is sent from memory to the printer
(I/O device). If the printer is busy, the OS can queue
the print job using spooling.

🧩 Example:

When you save a document, it is stored on the hard 🧠 Why It’s Important:
drive or SSD. The OS organizes the file and ensures
it is written to the correct location on the disk.  Prevents device conflicts by managing
access to hardware.
 Improves data transfer efficiency between
the CPU and external devices.
🧠 Why It’s Important:  Buffers data to prevent I/O bottlenecks.

 Ensures data integrity and organization.


 Optimizes disk access to reduce delays.
 Provides reliable storage for important data
5 Protection System
(e.g., backups).
💡 Definition:

The protection system ensures that the OS protects


4 I/O System Management data, memory, and hardware from unauthorized
access or corruption.
💡 Definition:
⚙️Functions:
I/O (Input/Output) management is responsible for
controlling and coordinating the flow of data  Access control: Ensures that only
between the CPU and external devices (such as authorized users or processes can access
printers, keyboards, and monitors). certain resources.
 User authentication: Verifies the identity
⚙️Functions: of users before allowing access to the
system.
 Device drivers: These are specific programs  Resource isolation: Prevents one process
that allow the OS to communicate with from accessing another’s data or code.
hardware devices.
P a g e 16 | 60
Operating system Final NOTES by anees ahmad
 Security mechanisms: Protects the system
from malicious threats and attacks (e.g.,
viruses, hackers). 🧩 Example:

When you browse a website, the OS manages the


networking aspect — it sends requests to the server,
🧩 Example: receives the response, and displays the webpage.

When you log into your computer with a username


and password, the OS checks if your credentials are
valid. Once authenticated, you’re granted access to 🧠 Why It’s Important:
specific resources based on your permissions.
 Allows communication between
computers over networks.
 Ensures data integrity and security during
🧠 Why It’s Important: transmission.
 Provides remote access capabilities (e.g.,
 Protects user data from unauthorized cloud services).
access.
 Ensures system stability by isolating
processes from one another.
 Defends against malicious software 7 Command Line Interpreter (CLI)
(viruses, malware).
💡 Definition:

The Command Line Interpreter (CLI) is a


6 Networking program that allows users to interact with the OS
using text-based commands (as opposed to
💡 Definition: graphical user interfaces).

Networking refers to the OS’s ability to manage ⚙️Functions:


communication between computers and other
devices over a network (like the internet or local  Command parsing: It reads and interprets
area network). user commands.
 Command execution: It executes the
⚙️Functions: command by interacting with the OS.
 Shell scripting: Supports the execution of
 Network protocols: Defines rules for how scripts that automate repetitive tasks.
data is transmitted (e.g., TCP/IP).
 Data transmission: Coordinates the sending
and receiving of data packets between
systems. 🧩 Example:
 Network security: Manages firewalls,
encryption, and secure connections. When you type ls in a Linux terminal, the CLI
 Remote access: Allows users to access the interprets the command and lists the files in the
computer or system remotely over a current directory.
network.
P a g e 17 | 60
Operating system Final NOTES by anees ahmad
🧠 Why It’s Important: Component Description Example

 Provides efficient control over system based form (CLI). Prompt.


operations for advanced users.
 Automates tasks via scripting.
 Offers a low-resource way of interacting
🧠 Operating System Services
with the OS, especially in servers or remote
systems. An Operating System provides various services to
facilitate smooth operation of programs and user
interactions with hardware. These services are
essentially the functions or features that the OS
provides to support user programs and manage
🧾 Summary Table: OS resources efficiently.
Components
Component Description Example

Manages processes, OS scheduling 1 Program Execution


Process
scheduling, and CPU time among
Management
multitasking. processes. 💡 Definition:
Manages memory Program Execution refers to the OS service that
Allocating
Main Memory (RAM), allocation, allows programs to be loaded into memory and then
memory to a
Management deallocation, and executed by the CPU.
running program.
protection.
⚙️How It Works:
Secondary Manages permanent Organizing files
Storage data storage and file on the hard drive
1. Loading: The OS loads the program (or
Management systems. or SSD. process) from disk into main memory
Manages
(RAM).
2. Execution: The CPU executes the
input/output Reading from a
I/O System instructions of the program.
devices, including disk or printing a
Management 3. The OS manages the CPU scheduling,
spooling and document.
ensuring that each process gets time to
buffering. execute and preventing one process from
Ensures data, monopolizing the CPU.
User
memory, and
Protection authentication 🧩 Example:
hardware are
System and access
protected from
control.  When you open Microsoft Word, the OS
unauthorized access.
loads the program into memory and then
Manages runs it, allowing you to interact with it.
Sending and
communication
Networking receiving data
between systems
over TCP/IP.
over a network.
🧠 Why It’s Important:
Command Line Interprets user Bash, PowerShell,
Interpreter commands in text- or Command

P a g e 18 | 60
Operating system Final NOTES by anees ahmad
 Multitasking: The OS needs to manage and 🧠 Why It’s Important:
execute multiple programs concurrently.
 Ensures fair allocation of CPU time to  Efficiency: Ensures that I/O devices are
different processes. utilized properly without affecting the
system’s performance.
 Concurrency: Allows multiple I/O
operations to occur simultaneously with
🧩 Analogy: CPU work.

Think of a chef starting to cook a dish.

 First, the chef needs to load the ingredients 🧩 Analogy:


(program) and then start cooking
(execution). Imagine you queue your laundry in a washing
machine. The washing machine (I/O device)
handles the washing while you continue with other
tasks. You don’t need to wait for the washing
2 I/O Operations machine to finish before starting other work
(buffering).
💡 Definition:

I/O Operations involve managing the input and


output devices, like keyboards, mice, monitors, 3 File System Manipulation
printers, and disks. The OS provides services to
control these devices and transfer data between the 💡 Definition:
CPU and devices.
The OS provides services to create, delete, read,
⚙️How It Works: write, and organize files on secondary storage
devices like hard drives and SSDs.
1. I/O Requests: A process makes an I/O
request to the OS (e.g., to write data to a file ⚙️How It Works:
or display something on the screen).
2. The OS handles the interaction with the 1. File Creation: The OS allocates space in
appropriate hardware, ensuring that data is storage for new files.
transferred correctly. 2. File Access: The OS manages access to
3. Buffering and spooling are used to manage files, ensuring the correct permissions and
slow I/O devices (e.g., disk drives or access control.
printers), allowing the CPU to continue 3. File Deletion: When a file is deleted, the OS
working while I/O operations complete. marks the space as free.
4. The OS provides file directories and file
🧩 Example: system structure to organize data
efficiently.
When you print a document, the OS manages the
data transfer from the application to the printer. 🧩 Example:

P a g e 19 | 60
Operating system Final NOTES by anees ahmad
When you save a file in a word processor, the OS In a chat application, the OS handles
writes the data to the disk, organizing it in a file communication between the sender and receiver,
directory structure (folders, files). ensuring that messages are delivered properly.

🧠 Why It’s Important: 🧠 Why It’s Important:

 Data Organization: Helps in the  Synchronization: Ensures processes don’t


systematic storage of data, making it easy interfere with each other during
to retrieve. communication.
 Ensures file security and access control.  Enables distributed computing (networked
systems).

🧩 Analogy:
🧩 Analogy:
Think of a librarian organizing books in a library.
The OS is the librarian who places each book in its Think of two people talking. The OS is like a
designated shelf and makes sure only authorized translator or interpreter who ensures both people
people can borrow the books. understand each other, even if they speak different
languages.

4 Communication Services
5 Error Detection
💡 Definition:
💡 Definition:
Communication services enable processes to
communicate with each other, either within the The OS monitors the system for errors and
same system (inter-process communication, IPC) provides mechanisms to handle them. Errors can be
or across systems (network communication). hardware-related (e.g., memory errors) or software-
related (e.g., invalid instructions).
⚙️How It Works:
⚙️How It Works:
1. Message Passing: Processes exchange data
using messages. 1. The OS continuously checks for faulty
2. Shared Memory: Multiple processes can hardware (e.g., disk failures, memory
access the same area of memory to issues).
communicate. 2. If a process encounters an illegal
3. The OS manages communication buffers instruction or invalid memory access, the
and synchronization between processes. OS detects it and can terminate or handle
the error.
🧩 Example: 3. Error logs may be maintained for
debugging purposes.

🧩 Example:
P a g e 20 | 60
Operating system Final NOTES by anees ahmad
If a program tries to access memory it doesn’t own
(segmentation fault), the OS detects the error and
terminates the program to prevent crashes. 🧠 Why It’s Important:

 Efficient resource usage maximizes system


performance.
🧠 Why It’s Important:  Ensures fair sharing of resources among
processes.
 Prevents system crashes.  Prevents resource starvation.
 Ensures stability and reliability.
 Helps diagnose hardware and software
issues.
🧩 Analogy:

Imagine a restaurant kitchen. The chef (OS)


🧩 Analogy: allocates cooking time and space for each dish
(process) to ensure that all orders are completed
Think of a safety system in a factory. If a machine efficiently and on time.
malfunctions (error), the system shuts it down to
prevent further damage or accidents.

7 Accounting

6 Resource Management 💡 Definition:


💡 Definition: Accounting refers to the OS's ability to track
resource usage and measure how much each
Resource management involves efficiently process or user consumes resources, such as CPU
allocating and managing system resources, such as time, memory, and I/O usage.
CPU time, memory, and I/O devices.
⚙️How It Works:
⚙️How It Works:
1. The OS tracks the amount of CPU time used
1. The OS tracks available resources (CPU by each process.
cycles, memory, disk space). 2. It also monitors disk space and network
2. It allocates resources to different processes usage by each user or process.
based on priority, need, and availability. 3. The OS can generate reports and provide
3. The OS ensures no resources are overused usage statistics.
or wasted, balancing the demands of
running processes. 🧩 Example:
🧩 Example: An OS in a multi-user system like a server might
track how much time each user spends using the
The OS allocates CPU time to different processes, CPU or network.
ensuring that the most important processes get
more resources while others wait their turn.

P a g e 21 | 60
Operating system Final NOTES by anees ahmad
🧠 Why It’s Important:  Prevents malicious attacks and data
breaches.
 Helps with resource allocation and billing  Ensures privacy and confidentiality.
(especially in cloud computing or shared  Keeps the system secure and prevents
systems). unauthorized actions.
 Allows performance monitoring and
optimization.

🧩 Analogy:

🧩 Analogy: Think of a bank vault. Only authorized personnel


(authenticated users) can access the vault. The
Think of a shared gym. The gym tracks how much vault’s protection system (OS) ensures that no one
time each member uses equipment (resource usage). can break in or alter the contents without
Based on this, the gym might charge members permission.
differently or restrict usage.

🧾 Summary Table: OS Services


8 Protection
Service Function Example
💡 Definition: Manages loading Running Word
Program
and running or a web
Protection ensures that resources are protected from Execution
programs. browser.
unauthorized access or modification. It includes
access control, data security, and protecting system Handles
integrity. Printing a
I/O Operations communication
document.
with I/O devices.
⚙️How It Works:
Manages file
1. Access Control Lists (ACLs): Defines what
File System creation, Saving and
each user or process can do with a resource.
2. User Authentication: Ensures that only Manipulation deletion, access, organizing files.
authorized users can access sensitive data or and storage.
execute critical operations.
3. The OS uses encryption and firewalls to Enables process Chat apps
protect data integrity and security. Communication communication exchanging
(IPC). messages.
🧩 Example:
Detects and
Segmentation
When you log into your computer, the OS handles errors in
Error Detection fault error
authenticates your username and password before software or
handling.
granting access to your files. hardware.

Resource Allocates and CPU time


Management tracks system allocation.
🧠 Why It’s Important:
P a g e 22 | 60
Operating system Final NOTES by anees ahmad
Service Function Example The Kernel can be thought of as the central
controller of a large orchestra. It manages all the
resources. instruments (hardware) and ensures the musicians
(programs) play in harmony without interrupting
Tracks resource each other.
Cloud
usage for
Accounting computing
processes and
usage tracking.
users.
🧩 2 What Are System Calls?
Ensures security
File access 💡 Definition:
and access
Protection control and
control to
encryption. A System Call (syscall) is a way for a user
resources.
program to interact with the kernel and request
services such as file operations, memory allocation,
process management, and communication with
devices.
🧠 Operating System Kernel &
System Calls  System Calls provide an interface between
the user space (where user programs run)
1 What is the OS Kernel?
and the kernel space (where the core
functions of the OS reside).
💡 Definition:
⚙️How It Works:
The Kernel is the core part of the Operating
System (OS). It is the central module that manages 1. A user program makes a system call (e.g., to
the hardware and software resources of the read a file).
computer, providing an interface between user 2. The program executes a software interrupt
applications and the physical hardware. to switch from user mode to kernel mode.
3. The OS kernel handles the request and
⚙️Functions of the Kernel: performs the required operation.
4. After the operation is completed, control is
 Process Management: Manages processes, returned to the user program.
including scheduling and execution.
 Memory Management: Handles memory
allocation and protection.
 Device Management: Manages all I/O 🧩 Example:
devices (keyboard, mouse, disk, etc.).
 System Security and Protection: Ensures When you open a file on your computer, the
processes and data are secure and isolated. operating system performs the open, read, and
 Communication Services: Allows write operations through system calls.
communication between processes and
between the OS and hardware.

🧩 Example: 🧠 Why System Calls Are Important:

P a g e 23 | 60
Operating system Final NOTES by anees ahmad
 Abstraction: They provide a high-level When you run a program, the OS uses system calls
abstraction, so user programs don’t need to like fork() to create a new process and exec() to
interact directly with hardware. execute it. If the program finishes, the OS uses
 Security: They control how processes exit() to clean up the process.
access resources, preventing malicious
actions.
 Efficiency: System calls allow programs to
perform complex tasks efficiently by
delegating them to the kernel.

🧩 3 Types of System Calls 🧩 Analogy:

There are several types of system calls, each serving Imagine a manager (OS) who assigns tasks
a different purpose. We will cover the five main (creates processes) to different workers.
types you should know for exams: If the task needs a new worker, the manager uses
fork() to hire them, and when the job’s done, the
1. Process Control manager calls exit() to dismiss the worker.
2. File Management
3. Device Management
4. Information Maintenance
5. Communication 2. File Management System Calls

Let’s explain each type in detail: 💡 Definition:

File management system calls allow programs to


interact with files — opening, reading, writing, and
1. Process Control System Calls closing files.

💡 Definition: ⚙️Common File Management Calls:

Process control system calls are used for managing  open(): Opens a file.
processes — starting, stopping, and controlling  read(): Reads data from a file.
processes running on the system.  write(): Writes data to a file.
 close(): Closes an opened file.
⚙️Common Process Control Calls:
🧩 Example:
 fork(): Creates a new process by duplicating
the current process. When you open a text file in a word processor:
 exec(): Replaces the current process with a
new one. 1. The OS uses open() to access the file.
 wait(): Makes the parent process wait until 2. The word processor uses read() to display
the child process finishes. its contents.
 exit(): Terminates a process. 3. You edit and the OS uses write() to save
changes.
🧩 Example:
P a g e 24 | 60
Operating system Final NOTES by anees ahmad
💡 Definition:

🧩 Analogy: These system calls manage system information


like time, process status, system parameters, and
Imagine you’re working in an office (OS) with user information.
documents (files).
To work on a document, you open it (open system ⚙️Common Information Maintenance
call), read it (read system call), and then close it Calls:
(close system call) when done.
 getpid(): Returns the process ID of the
current process.
 gettimeofday(): Gets the current time.
3. Device Management System Calls  uname(): Returns system information (e.g.,
OS name).
💡 Definition:
🧩 Example:
Device management system calls enable processes
to communicate with hardware devices, such as You can use getpid() to find the unique identifier of
input devices, printers, or storage devices. the running process, or gettimeofday() to check the
current system time.
⚙️Common Device Management Calls:

 ioctl(): Controls device behavior (e.g.,


screen brightness). 🧩 Analogy:
 read() and write(): Handle reading from or
writing to devices (like disks). Imagine a clock and directory on a wall. The OS
 close(): Closes the device file. can query the clock for time (gettimeofday()) or
check the directory for process details (getpid()).
🧩 Example:

When you send data to a printer, the OS uses


system calls to send the print job (via write()) to the 5. Communication System Calls
printer.
💡 Definition:

Communication system calls are used to enable


🧩 Analogy: processes to communicate with each other, either
within the same system (IPC) or over a network
Think of a printer (device). The OS is like a (network communication).
postman, who delivers documents (data) to the
printer. The postman uses system calls like write() ⚙️Common Communication Calls:
to deliver documents and close() when done.
 pipe(): Creates a pipeline for
communication between processes.
 shmget(): Allocates shared memory for
4. Information Maintenance System Calls communication.
P a g e 25 | 60
Operating system Final NOTES by anees ahmad
 msgget(): Creates a message queue for inter- Type Function Example
process communication.
processes
🧩 Example:

In a chat application, processes use IPC system


🧠 System Call Execution & OS
calls to send and receive messages, using shared Structures
memory or message queues.

1 System Call Execution

🧩 Analogy: 💡 What is System Call Execution?

Imagine two people (processes) communicating via When a user program needs to perform a privileged
phone lines (system calls). They can pass messages operation (such as accessing hardware resources or
through pipes or shared memory to coordinate interacting with the OS), it must use a system call
actions. to request that the OS execute the operation on its
behalf.

System Call Execution involves switching the


🧾 Summary Table: System program from user mode (where the program runs)
to kernel mode (where the OS operates with full
Calls control over hardware).
Type Function Example
⚙️Steps of System Call Execution:
Manage
processes
fork(), exec(), 1. User Mode to Kernel Mode Transition:
Process Control (create, o The user program executes a system
wait(), exit()
terminate, call (e.g., open(), read(),
synchronize) write()).
o This triggers a software interrupt
Manage files
File open(), read(), (often called a trap).
(open, read,
Management write(), close() o The program switches from user
write, close)
mode to kernel mode.
Control I/O 2. OS Handles the System Call:
Device ioctl(), read(), o The OS processes the system call
devices (printers,
Management write(), close() and performs the requested operation
disks, etc.)
(e.g., reading from disk, creating a
Retrieve system file).
getpid(), o The kernel takes control of the
Information information (PID,
gettimeofday(), hardware resources (memory, disk,
Maintenance time, system
uname()
parameters) etc.).
3. Return to User Mode:
Communication Facilitate pipe(), shmget(), o After the system call is executed, the
communication msgget() OS returns control to the program,
between switching it back to user mode.

P a g e 26 | 60
Operating system Final NOTES by anees ahmad
o The system call's result is then Semantics refers to the meaning and behavior of a
returned to the user program (e.g., a system call. It defines what the system call does and
file handle, a success/error code). what its expected result is.

For each system call, the OS provides a well-


defined behavior. This means that the OS ensures
🧩 Example: that:

1. You (User) want to open a file.  The correct action is taken.


2. You call the system call open(). The OS  The system call’s effects are predictable and
checks the request. consistent.
3. The OS opens the file, retrieves the  If an error occurs (e.g., trying to open a non-
contents, and gives you the file handle (a existent file), the OS provides an error code
reference to the file). or error message.
4. The OS returns to user mode, and you can
now work with the file. ⚙️Key Points of Semantics:

 Side Effects: The system call may have


effects on the state of the system (e.g.,
🧠 Why System Call Execution Is creating a new file, modifying memory).
Important:  Return Values: Each system call returns a
result or error code, indicating success or
 Abstraction: It provides an interface to failure (e.g., -1 for failure in some OSs).
interact with low-level hardware and OS  Blocking vs Non-blocking: Some system
resources without directly accessing them. calls may block the program (e.g., waiting
 Security: It prevents programs from for I/O) until completion, while others may
accessing critical system resources directly, return immediately.
ensuring that the OS controls access.

🧩 Example:
🧩 Analogy:
When a program calls read():
Think of ordering food in a restaurant. You (user)
make an order (system call). The waiter (OS) takes  Expected Result: The OS reads data from
your order and brings the food back to you. You the file and returns the data to the program.
don’t interact directly with the kitchen (kernel); the  If there’s an error (like trying to read from a
waiter does that on your behalf. non-existent file), the OS may return -1 with
an error code.

2 Semantics of System Call Execution


🧠 Why Semantics Matter:
💡 What is Semantics of System Call
Execution?  Predictability: Ensures that the OS behaves
consistently.

P a g e 27 | 60
Operating system Final NOTES by anees ahmad
 Error Handling: Defines how errors are  No clear separation between different OS
handled and reported to the user. components.
 The OS is typically faster but harder to
maintain and debug.
 Examples: MS-DOS, Unix (early versions)
🧩 Analogy:

Consider buying a coffee:


🧩 Example:
 You expect the barista (OS) to hand you a
coffee after you order (system call). In a simple structure OS, all the components —
 If there’s an issue (e.g., the coffee machine process management, memory management, file
is broken), you’ll get an error code (error system, and device drivers — are part of one
return value). monolithic program that directly manages the
system.

3 OS Structures
🧠 Why It’s Important:
The structure of the OS defines how the OS
components are organized and how they interact  Speed: Direct access to hardware and
with each other. There are several approaches to system resources.
structuring the OS, each with its own advantages  Simplicity: Easier to develop for smaller or
and challenges. single-purpose systems.

💡 Key OS Structures:

1. Simple Structure 2️ Layered Approach


2. Layered Approach
3. Microkernel
4. Virtual Machines
💡 Definition:

In the layered approach, the OS is divided into


layers, each with a specific function. Each layer
interacts only with the layers directly above and
1️ Simple Structure (Monolithic Kernel) below it.

💡 Definition: ⚙️Characteristics:
A simple structure OS is one where all OS  Each layer communicates only with
components are bundled together in a single large adjacent layers, providing modularity and
program. The entire OS runs in kernel mode, isolation.
providing direct access to hardware and system  More maintainable and easier to debug than
resources. a monolithic structure.
 Example: XNU (used by macOS), Theos
⚙️Characteristics: (used in embedded systems).

P a g e 28 | 60
Operating system Final NOTES by anees ahmad
In a microkernel system, the core kernel provides
basic services like memory management and inter-
🧩 Example: process communication (IPC), but device drivers,
file systems, and network protocols are handled by
In the layered approach: user-level processes.

 Layer 1: Hardware (CPU, memory, devices)


 Layer 2: Kernel (manages processes,
memory)
 Layer 3: File system management
 Layer 4: User interfaces and applications 🧠 Why It’s Important:

 Security: Reduces the risk of system crashes


(since user-space programs are isolated from
🧠 Why It’s Important: the kernel).
 Modularity: Easy to add new services
 Modularity: Each layer can be developed without modifying the kernel.
and tested independently.
 Flexibility: Layers can be replaced or
modified without affecting the entire OS.
4️ Virtual Machines (VMs)

💡 Definition:
3️ Microkernel
A Virtual Machine (VM) is a virtualized
💡 Definition: environment that allows the OS to run multiple
guest operating systems on top of a host OS.
The Microkernel approach divides the OS into a
small, minimal kernel that handles only essential ⚙️Characteristics:
services (e.g., process management,
communication), while other services (like device  A hypervisor (virtual machine monitor)
drivers, file systems) run in user space. manages the VM and allocates resources
between the host and guest operating
⚙️Characteristics: systems.
 Each VM operates as if it is running on its
 The kernel is minimal and focuses on own physical machine.
communication between processes.  Examples: VMware, VirtualBox, KVM
 Other OS services (e.g., device drivers) are
implemented as user-space programs,
making the system more flexible and secure.
 Examples: Minix, QNX, Mach 🧩 Example:

With a virtual machine, you can run Linux inside


a Windows OS. The host OS (Windows) runs the
🧩 Example: VM, and the guest OS (Linux) operates
independently within it.

P a g e 29 | 60
Operating system Final NOTES by anees ahmad
devices — and makes sure everything runs
smoothly.
🧠 Why It’s Important:
Think of it as the “manager” or “brain” of the
 Isolation: Each VM is isolated from others, computer that controls how every part works
providing security and stability. together.
 Flexibility: Multiple OS environments can
run on the same hardware, useful for testing
and development.
2. Major Components of Operating
System

There are five main components of an Operating


🧾 Summary Table: OS System:
Structures
Structure 1. Kernel
Characteristics Example 2. Process Management
Type
3. Memory Management
Simple All OS functions in one MS-DOS, early 4. File Management
Structure module. UNIX 5. Device Management
6. User Interface (Optional but often
OS divided into layers, included)
Layered XNU (macOS),
each with distinct
Approach Theos
functions. Let’s explain each one clearly 👇
Minimal kernel; other
Minix, QNX,
Microkernel services run in user
Mach
space.
1. Kernel
VMware,
Virtual Runs multiple guest OS Definition:
VirtualBox,
Machines on one host OS. The kernel is the core part of the OS. It directly
KVM
interacts with the hardware and controls all major
system operations like CPU, memory, and device
communication.
Components of Operating
Functions:
System
 Controls access to the CPU (who gets to use
it and when)
1. Introduction  Manages system calls (communication
between user programs and hardware)
An Operating System (OS) is a software that acts  Ensures security and stability of the system
as a bridge between the user and the computer
hardware. Analogy:
It manages all hardware and software resources — Think of the kernel as the heart of the human
like CPU, memory, storage, and input/output body — it keeps everything alive and running but

P a g e 30 | 60
Operating system Final NOTES by anees ahmad
works behind the scenes. Example:
Without it, the system can’t function. When you open multiple apps, the OS decides how
much memory each will get.

Analogy:
2. Process Management Like a hotel manager assigning rooms (memory) to
guests (processes). When a guest leaves, the room is
Definition: freed for others.
It handles the creation, scheduling, and
termination of processes (programs in
execution).
4. File Management
Functions:
Definition:
 Allocates CPU time to different processes It manages how data is stored, retrieved, and
 Keeps track of process states (running, organized on storage devices (like hard drives or
waiting, etc.) USBs).
 Prevents conflicts when multiple programs
run together Functions:

Example:  Creates, reads, writes, and deletes files


When you open a browser, a music app, and a Word  Manages directories and file permissions
document — the OS manages all these processes so  Keeps track of file locations
they don’t clash.
Example:
Analogy: When you save a document or open a photo, the OS
Like a traffic controller managing cars (processes) handles it through file management.
so they move smoothly without crashing.
Analogy:
Like a librarian — keeps track of all books (files),
knows where each is placed, and helps you find or
3. Memory Management store them.

Definition:
It manages the computer’s primary memory
(RAM) — deciding which program gets how much 5. Device Management
memory and when.
Definition:
Functions: It controls all input and output (I/O) devices such
as keyboard, mouse, printer, and USB drives.
 Keeps track of memory usage
 Allocates and deallocates memory when Functions:
needed
 Prevents one process from accessing  Uses device drivers to communicate with
another’s memory area (security) hardware
 Allocates devices to processes

P a g e 31 | 60
Operating system Final NOTES by anees ahmad
 Handles input/output requests from +-----------------------------+
programs | Hardware
|
Example: +-----------------------------+
When you print a document, the OS sends it to the
printer using the proper driver.
4. Quick Summary Table
Analogy: Component Function Analogy
Like a translator — it helps software “talk” to
Core of OS, controls
hardware devices in their own language. Kernel Heart of OS
system

Process Handles running Traffic


Management programs controller
6. User Interface (UI)
Memory Allocates/deallocates Hotel
Definition: Management memory manager
It is the part of the OS that interacts directly with
the user. File Manages data storage
Librarian
There are two main types: Management and access

 Command-Line Interface (CLI): User Device


Controls I/O devices Translator
types commands (e.g., DOS, Linux Management
Terminal)
User Interface Allows user interaction Receptionist
 Graphical User Interface (GUI): User
interacts through icons, menus, and
windows (e.g., Windows, macOS) System Design and
Analogy: Implementation (Operating
Like the receptionist in a company — it helps you System)
communicate with the system easily.
Basic Idea (In Very Simple Words)

System Design and Implementation means:


3. Diagram: Components of Operating
System How an Operating System is planned (designed)
+-----------------------------+ and built (implemented) so that users, system
| User Interface (UI) | administrators, and programs can use the
+-----------------------------+ computer efficiently, safely, and correctly.
| System Utilities / Shell |
+-----------------------------+ Think of an OS like a country:
| Process | Memory | File |
Device |
 Design = making laws and structure
 Implementation = actually running the
| Management Components
country using police, courts, systems
|
+-----------------------------+
| Kernel
|
P a g e 32 | 60
Operating system Final NOTES by anees ahmad
Main Parts of System Design & 2. System Administrator (Admin)
Implementation
Definition
These are very important for exams 👇
👉 User, System Administrator, Mechanism, A system administrator is a special user who
Policy, Language manages and controls the operating system.

I’ll explain one by one, then connect them. Simple Explanation

If users are drivers, admin is the traffic police 🚦


1. User Admin responsibilities:

Definition  Create/delete user accounts


 Assign permissions
A user is a person who uses the computer system to  Manage resources (CPU, memory, disk)
perform tasks like:  Install software
 Maintain security
 running programs
 storing files Example
 using applications
 Linux root user
Simple Explanation  Windows administrator

Users just want: 📌 Exam Tip:


👉 Admin has more privileges than normal users.
 system to be easy
 system to be fast
 system to be safe
3. Mechanism
They do not care how OS works internally.
Definition
Example
A mechanism is HOW something is done in the
 Student using MS Word OS.
 Programmer running code
 Gamer playing a game Simple Explanation
📌 Users interact with OS through: Mechanism = Tools / Methods / Procedures
provided by OS.
 GUI (Windows, Linux desktop)
 CLI (Terminal) It answers:

“How will the OS perform this task?”

Examples
P a g e 33 | 60
Operating system Final NOTES by anees ahmad
 Process scheduling mechanism 🔥 Mechanism vs Policy
 Memory allocation mechanism Mechanism Policy
 File access mechanism
 Synchronization mechanism (semaphores, HOW to do something WHAT to do
locks)
Implementation detail Decision rule
📌 Mechanism does NOT decide:
Low-level High-level
 who gets CPU Rarely changes Can change frequently
 which process has priority

It only provides the method. Best Analogy

 Mechanism = Traffic lights 🚦


4. Policy  Policy = Traffic rules (who stops, who goes)

📌 OS design separates policy from mechanism to:


Definition
 Make system flexible
A policy is WHAT decision is made using a  Change policies without rewriting code
mechanism.

Simple Explanation
5. Language (Implementation
Policy = Rules / Decisions Language)

It answers: Definition
“What should be done?” Language refers to the programming languages
used to implement the OS.
Examples
Simple Explanation
 Which process gets CPU first?
 Which user can access a file? OS must be:
 Which process has high priority?
 Fast
📌 Policies can be:  Efficient
 Close to hardware
 Fair
 Priority-based So languages are chosen carefully.
 Performance-based
Common Languages Used

 C → Most popular (UNIX, Linux)


 C++ → Object-oriented OS parts
 Assembly → Hardware-specific code
(booting, interrupts)
P a g e 34 | 60
Operating system Final NOTES by anees ahmad
📌 Mnemonic for languages: UNIX is a multiuser, multitasking operating
system originally developed in 1969 at AT&T Bell
“CAN OS” Labs.
C – Assembly – (C++) – OS
Simple Explanation

UNIX is like the father of modern operating


How All These Fit Together (Big systems.
Picture) Many OS ideas today come from UNIX.

 Users use applications Key Features of UNIX


 Admins manage system
 OS uses mechanisms to perform tasks  Multiuser (many users at same time)
 OS applies policies to decide rules  Multitasking (many processes at same time)
 OS is built using efficient languages  Stable and secure
 Mostly used in servers, mainframes,
enterprises
One-Line Summary
Examples of UNIX Systems
System design and implementation define how an
 AIX (IBM)
operating system is structured and built to manage
 HP-UX (Hewlett-Packard)
users, administrators, mechanisms, policies, and
 Solaris (Oracle)
programming languages efficiently.
📌 Important Exam Point:
UNIX is mostly commercial (paid).
Mnemonic to Remember Everything
Easily 🧠
2. What is Linux?
“U-S-M-P-L” → Use Smart Machines
Properly Lovingly 😄 Definition
 U → User Linux is a free and open-source operating system
 S → System Administrator developed by Linus Torvalds in 1991, inspired by
 M → Mechanism UNIX.
 P → Policy
 L → Language Simple Explanation
UNIX and Linux – Detailed Linux is like a free version of UNIX that anyone
Overview & Key Differences can:

 use
1. What is UNIX?  modify
 distribute
Definition
Key Features of Linux
P a g e 35 | 60
Operating system Final NOTES by anees ahmad
 Open source Feature UNIX Linux
 Secure and stable
 Multiuser & multitasking Developer AT&T Bell Labs Linus Torvalds
 Runs on:
Year 1969 1991
o PCs
o Servers Source Code Closed source Open source
o Mobiles (Android)
o Supercomputers Cost Mostly paid Free

Examples of Linux Distributions (Distros) Customization Limited Highly customizable

Hardware Support Limited Very wide


 Ubuntu
 Fedora Security Very high Very high
 Debian
 Red Hat User Base Enterprises Everyone
 Kali Linux
Updates Slow Frequent
📌 Mnemonic for Linux Distros:
Examples AIX, Solaris Ubuntu, Fedora
👉 “U Fancy Dogs Run Kindly”
(Ubuntu, Fedora, Debian, RedHat, Kali)

5. Architecture Similarity (UNIX &


Linux)
3. Relationship Between UNIX and
Linux Both follow same basic structure:

Very Important Concept User



 UNIX = Original OS Shell
 Linux = UNIX-like OS ↓
Kernel
Linux is NOT UNIX, but it behaves like UNIX. ↓
Hardware
Analogy
Explanation
 UNIX = Original recipe
 Linux = Improved, free version inspired  User: Person using system
by recipe  Shell: Interface (CLI)
 Kernel: Core of OS
 Hardware: CPU, memory, disk
4. Key Differences Between UNIX and
📌 Exam Tip:
Linux (⭐ Most Important Part ⭐) 👉 Mentioning architecture gives extra marks.

Comparison Table (Write This in Exam 💯)

P a g e 36 | 60
Operating system Final NOTES by anees ahmad
6. Why Linux Became More Popular 1. What is UNIX Directory Structure?
Than UNIX?
Definition (Exam-ready)
Reasons (Bullet Points for Exams)
The UNIX directory structure is a hierarchical
 Free and open source (tree-like) organization of files and directories
 Strong community support starting from the root directory (/).
 Easy to customize
 Runs on cheap hardware Simple Explanation
 Used in cloud, servers, Android
UNIX stores everything (files, folders, devices) in
one big tree 🌳
The root ( / ) is the starting point.
7. Security Comparison
Analogy
 UNIX → Secure by design
 Linux → Secure + frequent patches Think of UNIX like a family tree:
📌 Important Line for Exams:  /= great-grandfather
 Other directories = children & grandchildren
Linux security improves faster due to open-source
community.

2. Root Directory ( / )
8. Mnemonic to Remember
Very Important Point
Differences 🧠
 /is the top-most directory
“UNIX is COSTLY & CLOSED, Linux is  Every file and directory comes under /
FREE & FLEXIBLE”
📌 Exam Tip:
 UNIX → Paid, Proprietary 👉 Root / ≠ root user
 Linux → Free, Open Source (one is directory, other is admin user)

9. One-Line Summary 3. Important Directories in UNIX (Must


Remember)
UNIX is a commercial, stable operating system
developed at Bell Labs, while Linux is a free, open- I’ll explain one by one, in simple words.
source, UNIX-like operating system widely used
today.

Browsing Directory Structure /bin (Binary)


of UNIX
📌 Purpose

P a g e 37 | 60
Operating system Final NOTES by anees ahmad
 Contains basic user commands /etc contains system-wide configuration files.

📌 Examples 🧠 Mnemonic

ls ETC = Editable Technical Config


cp
mv
cat
/home
🧠 Mnemonic
📌 Purpose
BIN = Basic Instructions Needed
 Personal directories of users

📌 Example
/sbin (System Binary)
/home/anees
📌 Purpose /home/student

 System administration commands 📌 Analogy


 Used by root user
 Like user’s bedroom 🛏️
📌 Examples

reboot
shutdown /root
ifconfig
📌 Purpose
🧠 Mnemonic
 Home directory of root user
SBIN = System Boss Instructions Needed
📌 Important

 Different from /
/etc (Editable Text Configuration)

📌 Purpose
/usr (User System Resources)
 Configuration files of system
📌 Purpose
📌 Examples
 User-related programs and libraries
 user accounts
 passwords 📌 Contains
 network settings
/usr/bin
📌 Important Exam Line
P a g e 38 | 60
Operating system Final NOTES by anees ahmad
/usr/lib  USB
 Keyboard
📌 Exam Tip
📌 Exam Line
Most applications are stored in /usr
UNIX treats everything as a file.

/var (Variable files)


/lib (Libraries)
📌 Purpose
📌 Purpose
 Frequently changing files
 Shared libraries for programs in /bin and
📌 Examples /sbin

 Log files
 Mail files
 Printer queues /proc (Process information)
🧠 Mnemonic 📌 Purpose

VAR = Very Active Records  Information about running processes

📌 Important

/tmp (Temporary files)  Virtual directory (not real files)

📌 Purpose

 Temporary files created by programs 4. Diagram of UNIX Directory


Structure
📌 Important /
├── bin
 Deleted automatically ├── sbin
├── etc
├── home
├── root
/dev (Devices) ├── usr
├── var
📌 Purpose ├── tmp
├── dev
 Hardware devices represented as files ├── lib
└── proc
📌 Examples

 Hard disk
P a g e 39 | 60
Operating system Final NOTES by anees ahmad
5. Commands Used to Browse cd ..
cd ~
Directory Structure
📌 Special Symbols
Now the most practical part 👇
 . → current directory
 .. → parent directory

1. pwd (Print Working Directory)

📌 Use
4. tree
 Shows current directory
📌 Use
📌 Example
 Displays directory structure like a tree 🌳
pwd
tree /
/home/anees
📌 Exam Tip
2. ls (List) Not always installed by default.
📌 Use

 Lists files and directories


5. find
📌 Common Options
📌 Use
ls → simple list
 Search files/directories
ls -l → long list
ls -a → hidden files
find /home -name [Link]

🧠 Mnemonic

LS = Look Stuff 6. du (Disk Usage)

📌 Use

 Shows directory size


3. cd (Change Directory)
du -h
📌 Use

 Move between directories


7. stat
📌 Examples
📌 Use
cd /home
P a g e 40 | 60
Operating system Final NOTES by anees ahmad
 Detailed file information 1️What is a Process?

✅ Definition
6. Important Comparison (Exam Alert
A process is a program in execution, along with
🚨)
all the resources required to execute it.
/bin vs /sbin 📌 Very important line (write exactly like this):

/bin /sbin A process is an active entity that includes program


code, data, stack, program counter, CPU registers,
User commands Admin commands
and allocated resources.
Used by all users Used by root

ls, cp reboot, shutdown


🔹 Simple Explanation

7. Mnemonic to Remember Directories  A program is just a file stored on disk.


 When you run that program:
🧠
o it is loaded into memory
o CPU starts executing its instructions
“Be Safe Every Home User Visits The Dark ➡️Now it becomes a process
Library Properly”

 B → /bin
 S → /sbin 🔹 Program vs Process (Must-know
 E → /etc
 H → /home
comparison)
 U → /usr
 V → /var Program Process
 T → /tmp Passive Active
 D → /dev
 L → /lib Stored on disk Exists in memory
 P → /proc
No execution Executing

Single Many instances possible


8. One-Line Exam Summary

UNIX directory structure is a hierarchical 📌 Example


organization of directories starting from root (/)
used to manage files and system resources  [Link] → Program
efficiently.  Chrome running with 5 tabs → 5 processes

PROCESS (IN DETAIL)

P a g e 41 | 60
Operating system Final NOTES by anees ahmad
🔹 What Does a Process Contain? (VERY 2️A. CPU-Bound Process (IN DETAIL)
IMPORTANT)
✅ Definition
A process is not only code. It contains:
A CPU-bound process spends most of its time
1. Text section – program instructions executing on the CPU.
2. Data section – global variables
3. Heap – dynamic memory
4. Stack – function calls, local variables
5. CPU context – registers, program counter 🔹 Characteristics
6. Resources – files, I/O devices
✔️Long CPU bursts
📌 Writing these points gives extra marks. ✔️Very few I/O operations
✔️Performance depends on CPU speed

🔹 Real-Life Analogy
🔹 Examples
📘 Recipe vs Cooking
 Mathematical calculations
 Recipe book = Program  Video rendering
 Cooking in kitchen = Process  Scientific simulations
 Ingredients + stove + cook = Resources  Encryption algorithms

2️CPU-Bound and I/O-Bound Processes


🔹 Analogy
This topic is guaranteed in exams 🚨
Understand it using CPU burst concept. 🏃 Athlete running continuously

 Needs stamina (CPU)


 Rarely stops (I/O)
🔹 CPU Burst & I/O Burst (KEY IDEA)

A process executes in cycles:


🧠 Mnemonic
CPU Burst → I/O Burst → CPU Burst → I/O
Burst CPU-Bound → Calculation Power Used

 CPU burst = time spent using CPU


 I/O burst = time spent waiting for I/O
2️B. I/O-Bound Process (IN DETAIL)

✅ Definition

P a g e 42 | 60
Operating system Final NOTES by anees ahmad
An I/O-bound process spends most of its time Feature CPU-Bound I/O-Bound
waiting for I/O operations.
Example Calculations File read

🔹 Characteristics 3️Mechanism of Process Execution


(VERY IMPORTANT)
✔️Short CPU bursts
✔️Frequent I/O requests This explains HOW a process actually runs in the
✔️Performance depends on disk/network speed system.

🔹 Examples 🔹 Step-by-Step Mechanism of Process


Execution
 Reading files
 Printing 🟢 Step 1: Program Submission
 Web browsing
 Database queries  Program is submitted by user
 Stored on disk

🔹 Analogy
🟢 Step 2: Process Creation
📞 Person waiting for calls
 OS creates a PCB
 Short talking  Assigns PID
 Long waiting  Allocates memory & resources

📌 Program → Process

🧠 Mnemonic

I/O-Bound → Input/Output Busy 🟢 Step 3: Process Enters Ready State

 Loaded into main memory


 Waiting for CPU
🔥 CPU-Bound vs I/O-Bound (EXAM
TABLE)
Feature CPU-Bound I/O-Bound

CPU usage High Low


🟢 Step 4: CPU Allocation (Dispatch)

I/O waiting Low High  Short-term scheduler selects process


 Process enters Running state
CPU burst Long Short

P a g e 43 | 60
Operating system Final NOTES by anees ahmad
🟢 Step 5: Execution Cycle 🧠 MASTER MNEMONICS (REVISION
GOLD)
Process alternates between:
🔹 Process Definition
 CPU burst
 I/O burst
P-E-R-C
👉 Program Execution Requires Context
📌 If I/O needed → process blocked
📌 CPU given to another process
🔹 CPU vs I/O

👉 CPU thinks, I/O waits


🟢 Step 6: Context Switching

 Current process state saved in PCB ✨ FINAL 2-LINE SUMMARY


 Next process loaded
A process is an active program in execution that
uses CPU, memory, and I/O resources. Processes
execute through CPU and I/O bursts and are
🟢 Step 7: Process Termination managed by the OS using scheduling and context
switching.
 Execution completes
 Resources freed
 PCB destroyed PROCESS STATES & PROCESS
CONTROL BLOCK (PCB)
🔹 Process Execution Flow
Program → Process Creation → Ready → PROCESS STATES (IN DETAIL)
Running
→ Waiting (I/O) → Ready →
1️Why Do We Need Process States?
Running → Terminated

Drawing this gives full marks 💯 A computer can have:

 many processes
 only one CPU
4 Why This Mechanism Is Important?
So the OS must:
Because it allows:
✔️Multitasking  track what each process is doing
✔️CPU sharing  decide who gets the CPU
✔️High utilization
✔️Fair execution ➡️That’s why process states [Link] states
represent the current status of a process during its
execution.

P a g e 44 | 60
Operating system Final NOTES by anees ahmad
3️Explanation of Each Process State  Multiple apps open
(DETAILED)  Waiting for CPU turn

🟢 1. NEW STATE
📝 Exam Point
🔹 Meaning In the Ready state, the process is prepared to
execute and waiting for CPU allocation.
 Process is being created
 OS is:
o assigning Process ID (PID)
o creating PCB 🔴 3. RUNNING STATE
o allocating initial resources
🔹 Meaning
📌 Not yet in main memory
 Process is currently executing
 CPU registers are active
 Instructions are being executed
🧠 Example
📌 Only ONE process can be running per CPU
You double-click an application → process enters
NEW state

🧠 Example
📝 Exam Point A program currently using CPU

In the New state, the process has been created but is


not yet ready to execute.
📝 Exam Point

🟡 2. READY STATE In the Running state, the process has been assigned
the CPU and is executing instructions.
🔹 Meaning

 Process is: 🔵 4. WAITING (BLOCKED) STATE


o loaded into main memory
o has all resources except CPU 🔹 Meaning
 Waiting only for CPU
 Process cannot continue execution
📌 Most processes stay in this state  Waiting for:
o I/O operation
o event
o resource
🧠 Example
P a g e 45 | 60
Operating system Final NOTES by anees ahmad
📌 CPU is released for other processes 4️Process State Transitions (VERY
IMPORTANT)
From To

🧠 Example New → Ready Process admitted

 Waiting for file read Ready → Running CPU assigned


 Waiting for keyboard input
Running → Waiting I/O request

Waiting → Ready I/O completed

📝 Exam Point Running → Terminated Execution finished

In the Waiting state, the process is blocked until a


specific event occurs. 5️Process State Diagram (DESCRIBE
IN EXAM)
New → Ready → Running → Terminated

⚫ 5. TERMINATED STATE Waiting

🔹 Meaning (I/O Complete)

 Process execution is completed


🧠 Mnemonic for Process States
 OS:
o releases memory
NRRWT
👉 New Runners Run While Tired
o frees resources
o deletes PCB

PROCESS CONTROL BLOCK


(PCB)
🧠 Example What is Process Control Block (PCB)?
Closing an application
✅ Definition

A Process Control Block (PCB) is a data


structure maintained by the operating system
📝 Exam Point
that contains all information related to a process.
In the Terminated state, the process has finished
📌 Golden Line (Write exactly):
execution and is removed from the system.
PCB is the data structure that stores the complete
context of a process.

P a g e 46 | 60
Operating system Final NOTES by anees ahmad
7 Why PCB is Needed? 🔹 5. Memory Management Information

Because OS must:  Base & limit registers


 Page table pointer
 stop a process  Segment table
 resume it later
 track its state
 perform context switching
🔹 6. I/O Status Information
➡️Without PCB, multitasking is impossible
 Open files
 Allocated devices
 I/O requests
8 Information Stored in PCB (IN
DETAIL)

🔹 1. Process Identification 🧠 PCB Content Mnemonic

 Process ID (PID) PSCSMI


 Parent Process ID 👉 Process State Controls Scheduling Memory I/O

9 PCB MECHANISM & COMPLETE


🔹 2. Process State WORKING (STEP-BY-STEP)
 New, Ready, Running, Waiting, Terminated
This explains HOW PCB works internally 👇

🔹 3. CPU Context Information 🔹 Step 1: Process Creation

 Program Counter  Program starts


 CPU registers  OS creates PCB
 Stack pointer  Assigns PID
 Initializes PCB fields
📌 Needed for resuming execution
📌 PCB enters Ready Queue

🔹 4. Scheduling Information
🔹 Step 2: Process Execution
 Priority
 CPU usage  CPU scheduler selects process
 Queue pointers  PCB loaded into CPU
 Process enters Running state

P a g e 47 | 60
Operating system Final NOTES by anees ahmad
🔥 Key Exam Difference: PCB vs
🔹 Step 3: Context Switch Occurs Program
PCB Program
Triggered by: Data structure File

 timer interrupt Managed by OS Stored on disk


 I/O request
 higher priority process Dynamic Static

Needed for execution Needs PCB

🔹 Step 4: Saving Process State


🔚 FINAL SUMMARY
 CPU registers saved into PCB
 Program counter saved A process moves through different states during
 Process state updated execution, managed by the operating system. The
Process Control Block (PCB) stores complete
📌 This ensures no data loss information about each process and enables
multitasking through context switching.

🔹 Step 5: Loading Next Process


PROCESS SCHEDULING
 Next PCB loaded QUEUES (IN DETAIL)
 Registers restored
 Execution resumes
1 What is a Process Scheduling
Queue?
🔹 Step 6: Process Termination
✅ Definition
 Process finishes execution
 OS frees resources A process scheduling queue is a data structure
 PCB destroyed used by the operating system to organize
processes according to their current state during
execution.

🔁 PCB LIFE CYCLE 📌 Important


Process Created → PCB Created
Process Running → PCB Updated
Context Switch → PCB Saved
The operating system uses different queues to
Process Ends → PCB Deleted manage processes efficiently and allocate CPU and
I/O resources.

🔹 Simple Explanation

P a g e 48 | 60
Operating system Final NOTES by anees ahmad
Because:

 many processes exist 🔹 Key Characteristics


 CPU and I/O devices are limited
 Located on secondary storage (disk)
➡️OS lines up processes in queues, just like  Contains all new jobs
people standing in lines.  Managed by Long-Term Scheduler

📌 Exam Point:
2 Why Are Scheduling Queues
Job queue controls the degree of
Needed? multiprogramming.
Scheduling queues help OS to:

 decide which process runs next


🔹 What Happens Here?
 manage CPU sharing
 manage I/O waiting
 User submits program
 support multiprogramming
 Program becomes a process
 Process is placed in Job Queue
Without queues → chaos ❌
 OS decides when to admit it to memory

3 Types of Process Scheduling Queues


🔹 Analogy
There are three main queues (VERY
IMPORTANT): 🎓 University admission list

1. Job Queue  All applicants listed


2. Ready Queue  Only some selected at a time
3. Device Queue

🧠 Mnemonic
👉 J R D — Job Ready Device 5 READY QUEUE (IN DETAIL)

✅ Definition
4 JOB QUEUE (IN DETAIL)
The Ready Queue contains processes that are:

 in main memory
✅ Definition  ready to execute
 waiting only for CPU
The Job Queue contains all processes that are
created in the system but are not yet loaded into
main memory.

P a g e 49 | 60
Operating system Final NOTES by anees ahmad
🔹 Key Characteristics 🔹 Examples

 Located in RAM  Printer queue


 Most frequently used queue  Disk queue
 Managed by Short-Term Scheduler  Keyboard queue

📌 Exam Point: 📌 Exam Line:

Processes in ready queue have all resources except Each I/O device has its own device queue.
CPU.

🔹 Analogy
🔹 What Happens Here?
🖨️Printer line
 Process enters memory Only one job prints at a time
 Waits in ready queue
 CPU scheduler selects one
 Process moves to Running state
7 PROCESS MIGRATION
BETWEEN QUEUES (VERY
🔹 Analogy IMPORTANT)
🚦 Cars waiting at traffic signal This explains HOW processes move between
All ready, waiting for green light (CPU) queues during execution.

6 DEVICE QUEUE (IN DETAIL) 🔄 Step-by-Step Process Migration

🟢 Step 1: Job Submission


✅ Definition
 Program submitted
A Device Queue contains processes that are  Process created
waiting for a specific I/O device.  Added to Job Queue

🔹 Key Characteristics 🟢 Step 2: Admission to Memory

 One device → one queue  Long-term scheduler selects process


 Managed by I/O Scheduler  Process loaded into RAM
 Processes are in Waiting (Blocked) state  Moved to Ready Queue

P a g e 50 | 60
Operating system Final NOTES by anees ahmad
🟢 Step 3: CPU Allocation 1. Job Queue
o Stores all new processes
 Short-term scheduler selects process o Controls system load
 Process moves from Ready Queue → 2. Ready Queue
Running o Holds processes ready to run
o CPU scheduling happens here
3. Device Queue
o Handles I/O waiting
🟢 Step 4: I/O Request o Prevents CPU waste
4. Schedulers
 Running process requests I/O o Long-term → selects jobs
 CPU released o Short-term → selects CPU process
 Process moves to Device Queue o I/O scheduler → manages device
queues

📌 This coordination ensures:


🟢 Step 5: I/O Completion
 high CPU utilization
 I/O operation completes  fairness
 Process moves from Device Queue →  efficient execution
Ready Queue

🟢 Step 6: Process Termination 9 COMMON EXAM COMPARISON (VERY


USEFUL)
 Execution finished
 Process removed from system Queue Location Purpose Scheduler

Job Queue Disk All processes Long-term


🔁 MIGRATION FLOW DIAGRAM
Ready Queue RAM CPU waiting Short-term
Job Queue
↓ I/O
Device Queue RAM I/O waiting
Ready Queue ───► CPU (Running) scheduler
▲ │
│ ▼
Device Queue ◄── I/O Request 1 MNEMONICS FOR QUICK REVISION 🧠

8 COMPLETE MECHANISM (HOW OS 🔹 Queues


USES QUEUES)
👉 J R D — Job Ready Device
Let’s combine everything 👇
🔹 Migration

👉 Disk → RAM → CPU → Device → RAM


🔹 Mechanism of Process Scheduling
Queues

P a g e 51 | 60
Operating system Final NOTES by anees ahmad
🔚 FINAL SUMMARY
2️Why Scheduling is Needed?
Process scheduling queues are used by the operating
system to manage process execution efficiently.
Processes move between job, ready, and device Scheduling helps to:
queues based on CPU allocation and I/O requests,
ensuring proper scheduling and resource utilization.  maximize CPU utilization
 improve system performance
 ensure fairness
 support multitasking
 reduce waiting time
SCHEDULING (IN OPERATING
SYSTEM) 📌 Without scheduling → system becomes slow and
unfair ❌

1️What is Scheduling?
3️Types of Scheduling (VERY
✅ Definition
IMPORTANT)
Scheduling is the process by which the operating
system decides which process gets the CPU, There are three main types:
when, and for how long.
1. Long-Term Scheduling
📌 Golden exam line: 2. Short-Term Scheduling
3. Medium-Term Scheduling
Scheduling is the mechanism used by the operating
system to manage the execution of multiple 🧠 Mnemonic
processes by allocating CPU time. 👉 L-S-M → Large Small Medium
(helps remember the order)

🔹 Simple Explanation
4 LONG-TERM SCHEDULING
 Many processes want to use CPU (JOB SCHEDULER)
 CPU can run only one process at a time
➡️OS acts like a manager and schedules
them.
✅ Definition

Long-term scheduling decides which


jobs/processes should be admitted into main
🔹 Real-Life Analogy memory from the job queue.
🎤 Mic in a debate

 Many speakers want to talk


🔹 What It Controls
 One mic only
 Moderator decides who speaks and when
P a g e 52 | 60
Operating system Final NOTES by anees ahmad
✔️Number of processes in memory
✔️Degree of multiprogramming
5 SHORT-TERM SCHEDULING
📌 Degree of multiprogramming = number of
processes in memory (CPU SCHEDULER)
🔥 MOST IMPORTANT SCHEDULER 🔥

🔹 How It Works

1. Processes arrive in Job Queue (on disk) ✅ Definition


2. Long-term scheduler selects some
3. Selected processes loaded into memory Short-term scheduling decides which ready
4. Moved to Ready Queue process gets the CPU next.

🔹 Frequency 🔹 What It Controls

 Executes rarely ✔️CPU allocation


 Slow compared to others ✔️Context switching

🔹 Example 🔹 How It Works

 Selecting some applications to run while 1. Processes wait in Ready Queue


others wait 2. Short-term scheduler selects one
3. Dispatcher gives CPU to that process
4. Process enters Running state

🧠 Analogy

🎓 University admission office 🔹 Frequency

 Many applicants  Executes very frequently


 Only limited seats  Must be very fast
 Select some students

🔹 Example
📌 Exam Tip
 Choosing which app runs next on CPU
Long-term scheduler balances CPU-bound and I/O-
bound processes.

P a g e 53 | 60
Operating system Final NOTES by anees ahmad
🧠 Analogy 2. Medium-term scheduler swaps some out
3. Frees memory
🚦 Traffic signal 4. Later swaps them back

 Many cars waiting


 Signal decides who moves next
🔹 Frequency

 Executes occasionally
📌 Exam Tip  Less frequent than short-term

Short-term scheduler works with CPU scheduling


algorithms like FCFS, SJF, Round Robin.
🧠 Analogy

🧳 Temporary luggage storage


6 MEDIUM-TERM SCHEDULING
 Remove some bags to create space
(SWAPPER)  Bring them back later

✅ Definition
📌 Exam Tip
Medium-term scheduling temporarily removes
processes from memory to reduce system load and Medium-term scheduling helps prevent thrashing.
later brings them back.

7 COMPARISON TABLE
🔹 Key Concept: Swapping Medium-
Feature Long-Term Short-Term
Term
 Process removed → suspended
 Later reloaded → resumed CPU
Also called Job Scheduler Swapper
Scheduler

Which Which
Which jobs enter
🔹 What It Controls Decides
memory
process gets process to
CPU suspend
✔️Memory usage
✔️System performance CPU Memory
Controls Multiprogramming
allocation load

Frequency Low Very high Medium

🔹 How It Works Speed Slow Very fast Medium

1. Too many processes in memory

P a g e 54 | 60
Operating system Final NOTES by anees ahmad

8 HOW ALL SCHEDULERS Context switching allows multitasking by enabling


the CPU to switch from one process to another
WORK TOGETHER (BIG without losing progress of any process.
PICTURE)
1️Long-term scheduler admits jobs 2️Simple Explanation
2 Short-term scheduler selects CPU process
3️Medium-term scheduler manages memory by  CPU can execute only one process at a
swapping time
 There are many ready processes
➡️Together they ensure efficient execution  OS needs to pause one process and resume
another
 To do this, it saves the CPU state of the old
🧠 MASTER MNEMONIC (REVISION process and loads the CPU state of the new
process
GOLD)

👉 “Long admits, Short executes, Medium


suspends”
🔹 Analogy

🎬 Movie scenes on a projector


🔚 FINAL SUMMARY
 Current scene paused → projector
Scheduling is the process by which the operating remembers where it stopped
system allocates CPU time to processes. Long-term  Next scene loaded → plays from start of that
scheduling controls job admission, short-term scene
scheduling allocates CPU, and medium-term  Later, old scene can resume exactly from
scheduling manages memory by suspending where it paused
processes.

CONTEXT SWITCHING 3 What Exactly Is Saved During


(OPERATING SYSTEMS) Context Switch?

The OS stores the process context in the Process


1️Definition Control Block (PCB):

Context Switching is the process by which the 1. CPU Registers – current calculations
operating system saves the state of a currently 2. Program Counter – next instruction to
running process and loads the state of the next execute
process to be executed by the CPU. 3. Stack Pointer – function calls, local
variables
📌 Golden line for exams: 4. Memory management info – page/segment
tables
5. Process state – Running, Ready, Waiting

P a g e 55 | 60
Operating system Final NOTES by anees ahmad
📌 Without this, the process would lose progress  Allows CPU to share time fairly among
when switched out. processes
 Prevents CPU idling

4 When Does Context Switching


Occur? 7 Disadvantages / Cost

1. CPU Preemption – higher priority process  Overhead – CPU is doing no useful work
arrives while switching
2. I/O Request – process needs I/O device →  Frequent switches → performance drops
blocked  Requires fast memory access to PCB
3. Interrupts – timer or hardware interrupts
4. Process Termination – running process 📌 Exam Tip: Always mention “context switch
finishes overhead”

5 Step-by-Step Mechanism of Context 8 Analogy to Remember for Exam


Switching
🖥️Computer multitasking analogy:
1. Interrupt occurs → OS decides to switch
process  Think of a chef cooking 3 dishes
2. Save state of current process → registers,  Stops dish A to prepare dish B →
PC, stack, etc. to PCB remembers exact step
3. Update process state → Running → Ready  Later resumes dish A
or Waiting  This is context switching in real life
4. Select next process from Ready Queue
5. Load CPU state of next process from PCB
6. Resume execution of new process 9 Mnemonic (For Quick Revision)

“Save-Load-Resume”
🔹 Exam Diagram Save old, Load new, Resume execution

Running Process A
↓ (Interrupt / I/O)
Save State → PCB A 🔚 Final Summary

Load State → PCB B Context switching is the process of saving the state
↓ of a running process and loading the state of another
Running Process B process to allow multitasking. It ensures CPU
utilization and fairness but introduces overhead.

6 Why Context Switching Is Important

 Enables multitasking
P a g e 56 | 60
Operating system Final NOTES by anees ahmad

FORK() IN OPERATING 4 Example in C (Unix/Linux)


#include <stdio.h>
SYSTEMS #include <unistd.h>

1 Definition int main() {


int pid = fork();
Fork is a system call used in Unix/Linux to create
a new process by duplicating the calling (parent) if(pid == 0) {
process. printf("Child Process: PID =
%d\n", getpid());
📌 Exam line (write this): } else {
printf("Parent Process: PID =
The fork() system call creates a child process %d, Child PID = %d\n", getpid(), pid);
which is an exact copy of the parent process, except }
for some unique identifiers.
return 0;
}

2 Key Points About Fork 🔹 Explanation


1. Creates child process from parent process  fork() returns 0 to the child
2. Child is almost identical to parent:  fork() returns child PID to the parent
o Code section is shared  Both parent and child continue executing
o Data section copied after fork()
o Stack and heap copied
3. Each process has a unique Process ID
(PID)
4. Parent and child execute independently 5 Important Notes About Fork
Feature Parent Process Child Process

PID Unique Unique


3 How Fork Works (Mechanism)
PPID (Parent PID) N/A Parent PID
1. Parent process calls fork()
Memory Separate copy Separate copy
2. OS allocates PCB for child process
3. Copies process context (memory, CPU Execution Continues Starts after fork()
registers)
4. Assigns new PID to child Shared (copy-on-
Code Shared
5. Child process starts execution from the write)
point of fork()

📌 Important: Both processes continue executing the


next instruction after fork(), but PID 🔹 Copy-On-Write Optimization
distinguishes parent and child.
 Memory is not immediately copied
 Both share pages until modification
 Saves memory & improves performance
P a g e 57 | 60
Operating system Final NOTES by anees ahmad
2 Key Points About Threads
6 Analogy (For Easy Memory)
1. Multiple threads can exist within one
process
👨‍👦 Parent and Child 2. Threads share:
o Code segment
 Parent is a template o Data segment
 Child is born as almost identical copy o Open files
 Both can act independently 3. Threads have their own stack, registers,
 Only PID (identity) is different and program counter
4. Threads can execute concurrently

7 Exam Tip

 Draw Parent → fork() → Child diagram 🔹 Analogy (Easy to Remember)


 Mention return value of fork()
 Explain independent execution 📘 Thread as a worker in a company

🔚 Final Summary  Process = Company


 Threads = Employees
The fork() system call creates a new process by  Shared resources = Office, equipment
duplicating the calling process. The child process  Each thread can work independently but
has its own PID and executes independently, while shares resources
initially sharing code and data with the parent
process.
3 Advantages of Threads
THREADS IN OPERATING Advantage Explanation
SYSTEMS UI thread remains active while
Responsiveness
background threads execute
1 Definition
Threads share memory & resources
Resource Sharing
→ efficient
A thread is the smallest unit of CPU execution
within a process. Less overhead than creating new
It is sometimes called a “lightweight process”. Economical
processes

📌 Golden exam line: Better On multiprocessor systems, threads


Performance can run simultaneously
A thread is a basic unit of CPU utilization that
consists of a thread ID, program counter, register
set, and stack, and shares resources of its parent 4 Types of Threads
process.
🔹 1. User-Level Threads (ULT)

 Managed by thread library in user space


P a g e 58 | 60
Operating system Final NOTES by anees ahmad
 OS doesn’t know about them 📌 Exam Tip: Always mention that threads are
 Switching is fast lighter than processes, so switching is faster.
 Drawback: If one thread blocks → all
threads block

🔹 2. Kernel-Level Threads (KLT) 7 Thread vs Process (Exam Table)


Feature Process Thread
 Managed by OS kernel
Resource Shared within
 OS aware of each thread Independent
Sharing process
 Slower than ULT but better concurrency
 Each thread can be scheduled independently Creation Heavyweight Lightweight

🔹 3. Hybrid Threading Switching Slower Faster

 Combines user-level and kernel-level Memory Separate Shares memory


 User library maps threads to kernel threads
 Balance of speed and concurrency Execution Separate Can run concurrently

5 Thread Components (IN DETAIL) 8 Thread Mechanism / Execution

Each thread contains: 🔹 Step 1: Thread Creation

1. Thread ID (TID) – unique identifier  OS / thread library allocates stack and


2. Program Counter – next instruction registers
3. Registers – CPU context  Thread ID assigned
4. Stack – local variables & function calls  Added to Ready Queue

📌 Shared with other threads of the same process: 🔹 Step 2: Thread Scheduling

 Code segment  Scheduler selects thread from ready queue


 Data segment  CPU executes thread instructions
 Open files
🔹 Step 3: Thread Execution

 Thread shares process resources


6 Thread States  Executes function calls independently
Threads follow similar states as processes: 🔹 Step 4: Termination
 New – Thread created
 Thread finishes execution
 Ready – Waiting for CPU
 Stack and resources freed
 Running – Executing
 Process continues if other threads remain
 Waiting (Blocked) – Waiting for I/O or
event
 Terminated – Execution complete

P a g e 59 | 60
Operating system Final NOTES by anees ahmad
9 Real-Life Example

💻 Web Browser Example

 Main thread → UI rendering


 Worker thread → Fetching data from server
 Background thread → Loading images
All threads share memory but run
independently

🔟 Mnemonics for Quick Revision

 Threads share “C-D-F” → Code, Data,


Files
 Thread States → N R R W T (New Ready
Running Waiting Terminated)

🔚 Final Summary

Threads are lightweight units of execution within a


process, sharing code, data, and resources. They
improve performance and responsiveness, and can
be scheduled independently by the OS. Threads can
be user-level, kernel-level, or hybrid depending on
the system.

P a g e 60 | 60

You might also like