OS notes
OS notes
An Operating System (OS) is system software that acts as an interface between the user
and computer hardware.
Simple Explanation
● CPU
● RAM
● Hard Disk
● Keyboard
● Mouse
● Printer
The user cannot directly control all these hardware components. The Operating System
manages the hardware and allows the user to use the computer easily.
Simple Example
The OS tells the CPU, RAM, and other hardware what to do.
● Windows
● Linux
● macOS
● Android
● iOS
Main Idea
USER
↓
OPERATING SYSTEM
↓
HARDWARE
↓
CPU | RAM | DISK | KEYBOARD
1. Process Management
Example:
If you open Chrome, WhatsApp and MS Word at the same time, the OS manages all of them.
2. Memory Management
It:
Example:
When you open a large application, the OS gives it the required RAM.
3. File Management
● Create files
● Delete files
● Rename files
● Copy files
● Move files
● Organize files into folders
Example:
Windows File Explorer is used for file management.
4. Device Management
Examples:
● Keyboard
● Mouse
● Printer
● Scanner
● Hard disk
5. Security Management
The OS protects the computer and user data from unauthorized access.
Example:
● Password/PIN
● User accounts
● File permissions
6. User Interface
The OS provides an interface through which users can interact with the computer.
7. Resource Management
● CPU
● RAM
● Storage
● Input/Output devices
8. Error Management
Example:
If a device is not working properly, the OS may display an error message.
A Batch Operating System executes a group (batch) of similar jobs one after another
without direct interaction from the user.
Simple Explanation
In this system, the user gives many jobs to the computer. The OS collects them into a batch
and processes them one by one.
Example
Advantages
Disadvantages
Examples
● Payroll processing
● Bank statement generation
● Electricity bill processing
Simple Explanation
The CPU is very fast. If one program is waiting for input/output, the CPU can work on another
program.
RAM
┌─────────────────┐
│ Program 1 │
│ Program 2 │
│ Program 3 │
└─────────────────┘
↓
CPU
↓
Executes programs
Example
● MS Word
● Chrome
● Calculator
Advantages
Disadvantages
Simple Explanation
The CPU gives each task a small time slice called a time quantum.
CPU
↓
User 1 → small time
↓
User 2 → small time
↓
User 3 → small time
↓
User 1 → again
Because switching happens very quickly, users feel that they are using the computer
simultaneously.
Example
Advantages
Disadvantages
Simple Explanation
In a real-time system, time is very important. The system must respond quickly and correctly.
Examples
Example
Sensor detects danger
↓
RTOS
↓
Immediate response
↓
Airbag opens
Advantages
Disadvantages
● Expensive to develop.
● Complex.
● Requires highly reliable hardware/software.
A Mobile Operating System is an operating system designed specifically for mobile devices
such as smartphones and tablets.
Simple Explanation
Examples
● Android
● iOS
Main Functions
● Manages touchscreen.
● Manages mobile applications.
● Manages battery.
● Manages camera, microphone and sensors.
● Provides security.
● Manages Wi-Fi, Bluetooth and mobile networks.
Example
Mobile User
↓
Mobile Operating System
↙ ↓ ↘
Apps Hardware Network
Advantages
● Easy to use.
● Supports mobile applications.
● Provides touch-based interface.
● Supports wireless communication.
Disadvantages
Quick Comparison
Type Main Idea Example
A Command Line Interface (CLI) is an interface where the user interacts with the computer by
typing commands using the keyboard.
Simple Explanation
There are no buttons or graphical icons to click. The user types a command, and the computer
executes it.
Basic Structure
User
↓
Types Command
↓
Command Line Interface
↓
Operating System
↓
Hardware
Examples
Example
dir
Another example:
cd documents
Advantages of CLI
Disadvantages of CLI
A Graphical User Interface (GUI) allows users to interact with the computer using windows,
icons, menus, buttons and a mouse/touchpad.
Simple Explanation
Instead of typing commands, the user can click icons and buttons to perform tasks.
Basic Structure
User
↓
Mouse / Keyboard / Touch
↓
GUI
↓
Operating System
↓
Hardware
Examples
● Windows
● Linux
● macOS (Mac OS)
Example
Advantages of GUI
Disadvantages of GUI
CLI vs GUI
Feature CLI GUI
Operating System Services are the facilities provided by the OS to make it easy for users and
application programs to use the computer.
Simple Explanation
The OS works like a manager. It provides different services to programs and users.
1. Program Execution
Example:
When you open Chrome, the OS loads Chrome into memory and starts it.
2. Input/Output Operations
Examples:
● Keyboard
● Mouse
● Printer
● Monitor
● Disk
Example:
When you type using a keyboard, the OS manages the input.
It allows us to:
● Create files
● Delete files
● Open files
● Read/write files
● Rename files
4. Communication
Example:
Two programs running on a computer may need to communicate with each other.
5. Error Detection
● CPU
● Memory
● Storage
● Input/output devices
● Programs
6. Resource Allocation
Resources include:
● CPU
● Memory
● Storage
● I/O devices
Example:
If multiple programs need CPU time, the OS decides which program gets the CPU.
Examples:
● Passwords
● User accounts
● File permissions
8. User Interface
Types:
2. System Call
Concept of System Call
Definition
A System Call is a mechanism through which a user program requests a service from the
Operating System.
Simple Explanation
Simple Example
Suppose a program wants to read a file.
Application Program
↓
System Call
↓
Operating System
↓
File / Disk
The OS performs the operation and returns the result to the program.
● Creating a process
● Opening a file
● Reading a file
● Writing to a file
● Allocating memory
● Communicating with another process
● Accessing devices
1. Process Control
Used to create, execute and terminate processes.
Examples:
● Create process
● End process
● Load program
● Execute program
● Wait for a process
Example:
When you start a program, the OS creates a process for it.
2. File Management
Used to manage files and directories.
Examples:
● Create file
● Open file
● Read file
● Write file
● Close file
● Delete file
Example:
3. Device Management
Used to control and access hardware devices.
Examples:
● Request a device
● Release a device
● Read from a device
● Write to a device
Example:
A program requests the OS to send data to a printer.
4. Information Maintenance
Used to get or change system information.
Examples:
Example:
An application asks the OS for the current date and time.
5. Communication
Used for communication between processes or systems.
Examples:
● Send message
● Receive message
● Create communication connection
● Share information between processes
Example:
Two processes exchange data using communication system calls.
P–F–D–I–C
● P → Process Control
● F → File Management
● D → Device Management
● I → Information Maintenance
● C → Communication
System Call:
A system call is a mechanism used by a user program to request services from the Operating
System.
1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication
1. Process Management
2. Main Memory Management
3. File Management
4. I/O Management
5. Secondary Storage Management
1. Process Management
Definition
Simple Explanation
The OS:
● Creates processes
● Deletes processes
● Schedules processes
● Suspends and resumes processes
● Allocates CPU to processes
Example
If you open:
All three are running processes. The OS decides which process gets CPU time and when.
Simple Diagram
Operating System
↓
Process Management
↙ ↓ ↘
Chrome Word Calculator
Simple Explanation
Example
If Chrome requires 500 MB RAM, the OS allocates the required memory to Chrome.
When Chrome is closed, the OS can make that memory available for another program.
Simple Diagram
RAM
┌──────────────────┐
│ Chrome │
│ MS Word │
│ Operating System │
│ Free Memory │
└──────────────────┘
↑
│
Memory Management
3. File Management
Definition
File Management is the OS component responsible for managing files and directories
(folders).
Simple Explanation
● Create files
● Delete files
● Open files
● Read files
● Write files
● Rename files
● Create/delete folders
Example
Documents
↓
Student [Link]
4. I/O Management
I/O = Input/Output
Definition
I/O Management manages communication between the computer and input/output devices.
Input Devices
● Keyboard
● Mouse
● Scanner
● Microphone
Output Devices
● Monitor
● Printer
● Speaker
Simple Explanation
Example
When you type:
Keyboard → OS → Application
Application → OS → Printer
Secondary Storage Management manages permanent storage devices such as hard disks
and SSDs.
Examples
● HDD
● SSD
● USB drive
● Memory card
Simple Explanation
RAM is temporary memory, but secondary storage is used to store data permanently.
The OS manages:
● Free space
● Storage allocation
● File locations
● Disk scheduling
Example
Application
↓
Operating System
↓
SSD / HDD
↓
File Stored Permanently
P–M–F–I–S
P → Process Management
M → Main Memory Management
F → File Management
I → I/O Management
S → Secondary Storage Management
Simple Example
[Link] → Program
So:
2. Process States
A process does not remain in the same state during its entire execution. It moves through
different states.
1. New
2. Ready
3. Running
4. Waiting/Blocked
5. Terminated
┌─────────┐
│ New │
└────┬────┘
┌─────────┐
│ └────┬────┘ │
│ ↓ │
│ ┌─────────┐ │
│ │ Running │ │
│ └────┬────┘ │
│ ↙ ↘ │
│ ↓ ↓ │
│ Waiting │ │ Terminated │
└────┬────┘ └────────────┘
└────────→ Ready
Example:
You click on MS Word to open it. The OS starts creating the process.
2. Ready State
Example:
Process A → Ready
Process B → Ready
Process C → Ready
3. Running State
Example:
MS Word is currently executing instructions on the CPU.
The process is waiting for something, usually an I/O operation or another event.
Example:
Waiting
Data received
Ready
5. Terminated State
Example:
You close MS Word → Word process is terminated.
A Process Control Block (PCB) is a data structure maintained by the Operating System that
contains important information about a process.
Simple Explanation
PROCESS
┌─────────────────┐
│ PCB │
├─────────────────┤
│ Process ID │
│ Process State │
│ Program Counter │
│ CPU Registers │
│ CPU Scheduling │
│ Memory Info │
│ I/O Information │
└─────────────────┘
Example:
2. Process State
For example:
● New
● Ready
● Running
● Waiting
● Terminated
3. Program Counter
Stores the address of the next instruction that the process needs to execute.
4. CPU Registers
For example:
● Process priority
● Scheduling information
Contains information about the I/O devices and files being used by the process.
● Identify a process.
● Track the process state.
● Manage CPU scheduling.
● Manage memory.
● Manage I/O.
● Perform context switching.
CPU → Process A
CPU → Process B
The PCB allows the OS to save and restore the information needed to continue a process later.
Quick Revision
Process States
PCB
Easy Trick
P-S-P-C-S-M-I
● P → Process ID
● S → Process State
● P → Program Counter
● C → CPU Registers
● S → Scheduling Information
● M → Memory Information
● I → I/O Information
Process Scheduling
1. Process Scheduling
Definition
Process Scheduling is the method used by the Operating System to select a process from
the ready processes and give it the CPU.
Simple Explanation
Many processes may be waiting to use the CPU, but usually only one process can use a CPU
core at a time.
The OS uses a CPU Scheduler to decide which process should run next.
Process A ─┐
Process B ─┤
Process D ─┘
2. Scheduling Queues
A scheduling queue is a list of processes waiting for a particular resource or stage of
execution.
1. Job Queue
Contains all processes that are waiting to enter the system for execution.
New Processes
Job Queue
2. Ready Queue
Contains processes that are ready to run and waiting for the CPU.
P1 ─┐
P2 ─┤
P4 ─┘
3. Device Queue
Examples:
● Printer
● Disk
● Keyboard
● Network device
Process
I/O Request
Device Queue
I/O Device
3. Types of Schedulers
A scheduler is an OS component that selects processes for execution.
1. Long-Term Scheduler
Definition
The Long-Term Scheduler selects processes from the job queue and loads them into the
ready queue.
Simple Explanation
Job Queue
Long-Term Scheduler
Ready Queue
Main Purpose
2. Short-Term Scheduler
Definition
The Short-Term Scheduler selects a process from the ready queue and gives it the CPU.
Simple Explanation
It decides:
Ready Queue
Short-Term Scheduler
↓
CPU
Important Point
3. Medium-Term Scheduler
Definition
The Medium-Term Scheduler temporarily removes processes from memory and later brings
them back.
Simple Explanation
If memory becomes full, the OS may temporarily move a process out of memory.
Memory
Medium-Term Scheduler
Disk
Later → Memory
Main Purpose
Easy Trick
Long → Enter
Short → CPU
Medium → Swap
5. Context Switch
Definition
A Context Switch is the process of saving the state of one process and loading the state of
another process.
Simple Explanation
First, the OS saves Process A's information in its PCB and then loads Process B's information.
CPU
↓
Process A
PCB A
PCB B
Process B
CPU
What is Saved?
● Program Counter
● CPU Registers
● Process State
● Other CPU-related information
Student A
↓
Teacher saves where they stopped
Student B
Teacher checks B
Returns to Student A
Similarly, the CPU switches between processes and continues each process from where it
stopped.
Long-Term Scheduler
READY QUEUE
Short-Term Scheduler
│
↓
CPU
↙ ↘
│ │
│ ↓
│ DEVICE QUEUE
│ │
│ ↓
└──────────→ READY
Medium-Term Scheduler can temporarily move processes between memory and secondary
storage through swapping.
⭐ Exam Revision
Scheduling Queues
Types of Schedulers
Simple Explanation
For example:
The Operating System provides IPC mechanisms to make this communication possible.
In a Shared Memory System, two or more processes communicate by using a common area
of memory.
Simple Explanation
Process A
↓
┌───────────────┐
│ Shared Memory │
└───────────────┘
Process B
Process A can write data into shared memory, and Process B can read that data.
Example
Process A
Writes Data
Shared Memory
Reads Data
Process B
Advantages
Disadvantages
Simple Explanation
Processes do not need to share the same memory. Instead, one process sends a message and
another process receives it.
Process A
│ Send Message
Operating System
│ Receive Message
Process B
Example
Process A sends:
"Data is ready."
Send
Process A
send(message)
Receive
Process B
receive(message)
Disadvantages
Easy Diagram
INTER-PROCESS COMMUNICATION
┌───────┴───────┐
↓ ↓
│ │
│ │
Shared Memory
Message Passing
IPC:
Inter-Process Communication is a mechanism that allows processes to communicate and
exchange data with each other.
Types of IPC:
Threads
1. What is a Thread?
Definition
Simple Explanation
Think of a process as a restaurant and threads as workers working inside the restaurant.
PROCESS
┌─────────────┐
│ │
│ Thread 1 │
│ Thread 2 │
│ Thread 3 │
│ │
└─────────────┘
Example
● Loading a webpage
● Playing video
● Downloading a file
● Handling user input
2. Benefits of Threads
1. Responsiveness
Example:
A browser can continue responding while a webpage is loading.
2. Resource Sharing
● Code
● Data
● Files
● Memory
3. Economy
Creating and managing threads generally requires less overhead than creating separate
processes.
4. Faster Execution
Multiple threads can execute concurrently and, on multicore systems, can run in parallel.
Threads can keep the CPU busy while another thread is waiting for I/O.
3. Types of Threads
There are two main types:
1. User-Level Threads
2. Kernel-Level Threads
4. User-Level Threads
Definition
User-level threads are managed by a user-level thread library, without direct management by
the OS kernel.
Simple Explanation
User Process
┌─────────────┐
│ Thread 1 │
│ Thread 2 │
│ Thread 3 │
└─────────────┘
Kernel
Advantages
● Faster to create.
● Faster to switch between threads.
● Does not require frequent kernel involvement.
Disadvantages
● If one thread makes a blocking system call, the entire process may be blocked in many
user-level implementations.
● The kernel may not schedule individual user threads separately.
5. Kernel-Level Threads
Definition
Simple Explanation
Process
┌─────────────┐
│ Thread 1 │
│ Thread 2 │
│ Thread 3 │
└──────┬──────┘
Kernel
CPU
Advantages
Disadvantages
Kernel Kernel may not know individual threads Kernel knows threads
awareness
Blocking Can block the whole process in many Other threads can
implementations continue
7. Multithreading Models
A multithreading model describes the relationship between user threads and kernel threads.
1. Many-to-One
2. One-to-One
3. Many-to-Many
8. Many-to-One Model
Definition
In the Many-to-One model, many user-level threads are mapped to one kernel thread.
─────────────
Thread 1 ───┐
Thread 3 ───┘
Simple Explanation
Advantage
Disadvantage
● If one thread makes a blocking system call, the entire process may block.
● Cannot achieve true parallel execution of these threads on multiple CPU cores.
9. One-to-One Model
Definition
In the One-to-One model, each user thread is mapped to one kernel thread.
Simple Explanation
Advantages
Disadvantage
In the Many-to-Many model, many user-level threads are mapped to multiple kernel threads.
Thread 1 ────────┐
Thread 3 ────────┤
Simple Explanation
Many user threads can be mapped to a smaller or equal number of kernel threads.
Advantages
● Provides good concurrency.
● Can support parallel execution.
● Avoids creating a kernel thread for every user thread.
Disadvantage
Many-to-One Many user → One Simple and fast No true parallelism; blocking can
kernel affect all
Many → One
👥👥👥 → 🖥️
One → One
👤 → 🖥️
👤 → 🖥️
👤 → 🖥️
Many-to-Many
Many → Many
👥👥👥👥 → 🖥️🖥️🖥️
⭐ Exam Revision
Thread: Smallest unit of execution within a process.
Benefits of Threads:
1. Responsiveness
2. Resource sharing
3. Economy
4. Faster execution
5. Better CPU utilization
Types:
● User-Level Threads
● Kernel-Level Threads
Multithreading Models:
1. top Command
Definition
The top command is used to display currently running processes and system resource
usage.
Simple Explanation
top
It displays:
● Process ID (PID)
● CPU usage
● Memory usage
● Process name
● Process status
Example
top
2. ps Command
Definition
Example
ps
Common command
ps -ef
Important information:
● PID
● User
● CPU time
● Command
● Process status
ps top
Syntax
kill PID
Example
kill 1234
Force termination
kill -9 1234
Important: kill does not always mean "immediately delete a process"; it sends a
signal, and the process may handle some signals.
4. wait Command
Definition
Simple Example
sleep 5 &
wait
Here:
● sleep 5 & starts a background process.
● wait makes the shell wait until that process finishes.
Simple Meaning
5. sleep Command
Definition
Example
sleep 5
Another example:
sleep 10
Simple Meaning
6. exit Command
Definition
Example
exit
After executing it, the current terminal shell closes or returns to its parent shell.
exit 0
exit 1
Simple Meaning
7. nice Command
Definition
The nice command is used to start a process with a specified scheduling priority
(niceness).
Simple Explanation
Example
nice -n 10 myprogram
Important Point
Simple Meaning