Master the fundamentals of Operating Systems with clear explanations, diagrams, and hands-on examples
0 / 11 topics completed
01
Introduction to Operating Systems
An Operating System (OS) is system software that manages computer hardware and software resources and provides common services for computer programs. It acts as an intermediary between users and the computer hardware.
What is an Operating System?
An OS is a software layer that manages hardware resources (CPU, memory, storage, I/O devices) and provides a convenient interface for users and applications to interact with the system.
Why is an OS Important?
Resource Management β Efficiently allocates CPU time, memory, and I/O
Abstraction β Hides complex hardware details from users
Popular OS examples: Windows (desktop), Linux (servers/embedded), macOS (Apple), Android (mobile), and iOS (Apple mobile).
02
Types of Operating Systems
Operating Systems can be categorized based on how they manage users, tasks, and resources.
Type
Description
Example
Batch OS
Jobs with similar needs are grouped and executed without user interaction
IBM OS/360
Time-Sharing OS
CPU time is sliced and shared among multiple users giving illusion of dedicated system
UNIX, Linux
Distributed OS
Multiple interconnected computers share resources and appear as a single system
Google File System, LOCUS
Real-Time OS (RTOS)
Guarantees task completion within strict time constraints
FreeRTOS, VxWorks
Mobile OS
Designed for mobile devices with touch input and power efficiency
Android, iOS
Network OS
Runs on servers and manages network resources, users, and permissions
Windows Server, Novell NetWare
π‘
Hybrid OS combine features from multiple types. Modern OS like Linux and Windows use elements of time-sharing, real-time, and network OS all at once.
Practice: Types of OS
Which type of OS is best suited for a nuclear power plant control system? Why?
What makes Time-Sharing OS different from Batch OS?
Name two examples of Mobile Operating Systems.
1. Real-Time OS (RTOS) β because it guarantees task completion within strict deadlines, which is critical for safety.
2. Time-Sharing OS provides interactive response to multiple users simultaneously by slicing CPU time, whereas Batch OS executes jobs in groups without user interaction.
3. Android and iOS.
03
Functions of an Operating System
An OS provides several essential functions that manage system resources and enable smooth operation.
1. Process Management
Handles creation, scheduling, and termination of processes. Manages synchronization and communication between processes.
2. Memory Management
Allocates and deallocates memory to processes. Implements virtual memory and handles paging/segmentation.
3. File System Management
Organizes files into directories, manages file permissions, and handles read/write operations on storage devices.
4. Device Management
Manages I/O devices through drivers, handles interrupts, and buffers data transfers between devices and memory.
5. Security & Protection
Controls access to resources through authentication, authorization, and encryption mechanisms.
The OS manages all these functions simultaneously. When you open a file, the OS verifies permissions, loads data from disk into memory, and makes it available to your application β all behind the scenes.
04
Process Management
A process is a program in execution. Each process has its own memory space, program counter, and system resources.
Processes vs Threads
Process β Heavyweight, isolated memory space, independent execution
Thread β Lightweight, shares memory within a process, multiple threads per process
Process States
A process goes through several states during its lifecycle:
When the CPU switches from one process to another, it saves the current process state (registers, program counter) and loads the saved state of the next process. This is called context switching.
Aspect
Process
Thread
Memory
Separate address space
Shared within process
Creation Time
Slower
Faster
Context Switch
Expensive
Cheap
Isolation
Fully isolated
Can affect sibling threads
Communication
IPC (pipes, sockets)
Shared memory
Practice: Process Management
List the five states a process can be in.
What is the difference between a process and a thread?
2. A process has its own separate memory space while threads share memory within a process. Processes are heavyweight; threads are lightweight.
3. Context switching takes CPU time to save and restore process states. During this time, no useful work is done, which is why it's considered overhead.
05
CPU Scheduling Basics
CPU Scheduling determines which process gets the CPU and for how long. The goal is to maximize CPU utilization, throughput, and fairness while minimizing wait time and response time.
1. First-Come, First-Served (FCFS)
The simplest algorithm. Processes are executed in the order they arrive. Non-preemptive β once a process gets the CPU, it runs to completion.
Example
Process Burst Time Arrival Time
P1 5 0
P2 3 1
P3 8 2
FCFS Order: P1 β P2 β P3
Completion Times: P1=5, P2=8, P3=16
Avg Wait Time: (0 + 4 + 6) / 3 = 3.33 ms
2. Shortest Job First (SJF)
Executes the process with the smallest burst time first. Can be preemptive (SRTF) or non-preemptive. Minimizes average waiting time.
Each process gets a fixed time quantum (e.g., 4ms). Processes are scheduled in a circular queue. If a process doesn't finish within its quantum, it's preempted and moved to the end of the queue.
Each process has a priority. The CPU is allocated to the process with the highest priority. Can be preemptive or non-preemptive. May cause starvation for low-priority processes.
Algorithm
Preemptive
Starvation
Avg Waiting Time
FCFS
No
No
High (convoy effect)
SJF
Optional
Possible
Optimal
Round Robin
Yes
No
Depends on quantum
Priority
Optional
Yes (low priority)
Moderate
Practice: CPU Scheduling
Three processes arrive at time 0: P1 (burst 10ms), P2 (burst 5ms), P3 (burst 8ms).
What is the FCFS order and average waiting time?
What is the SJF order and average waiting time?
With Round Robin (quantum = 4ms), what is the order of execution?
Memory Management handles how memory is allocated to processes, how addressing works, and how the system maximizes memory utilization.
Paging
Physical memory is divided into fixed-size blocks called frames. Process memory is divided into blocks of the same size called pages. A page table maps logical pages to physical frames, eliminating external fragmentation.
Memory is divided into variable-sized segments (code, data, stack, heap). Each segment has a base address and limit. Supports logical division of a program but can cause external fragmentation.
Virtual Memory
Allows execution of processes that are not entirely in memory. Uses paging with demand paging β pages are loaded only when needed. This enables running larger programs than physical RAM allows.
π‘
Virtual memory is supported by the MMU (Memory Management Unit) hardware. When a required page is not in RAM, a page fault occurs and the OS loads it from disk.
Practice: Memory Management
What is the difference between paging and segmentation?
What happens during a page fault?
Why is virtual memory useful?
1. Paging uses fixed-size blocks and eliminates external fragmentation. Segmentation uses variable-sized logical segments (code, data, stack) but can cause external fragmentation.
2. A page fault occurs when a process tries to access a page not in RAM. The OS loads the required page from disk (swap space) into a free frame and updates the page table.
3. Virtual memory allows running programs larger than physical RAM, enables efficient memory sharing, and simplifies memory management for programmers.
07
Deadlocks Introduction
A deadlock is a situation where two or more processes are unable to proceed because each is waiting for a resource held by another.
Four Necessary Conditions for Deadlock
Mutual Exclusion β Resources cannot be shared; only one process at a time
Hold and Wait β A process holds at least one resource while waiting for others
No Preemption β Resources cannot be forcibly taken from a process
Circular Wait β A circular chain of processes exists where each holds a resource needed by the next
Mutual Exclusion β Use spooling or shareable resources (not always possible)
Hold and Wait β Require processes to request all resources at once
No Preemption β Allow preemption of resources
Circular Wait β Impose a total ordering of resource types
Deadlock Avoidance β Banker's Algorithm
The OS simulates resource allocation and only grants a request if the resulting state is safe (all processes can eventually complete). This is known as the Banker's Algorithm.
β οΈ
Deadlock detection allows deadlocks to occur but identifies them using wait-for graphs. Deadlock recovery involves killing processes or preempting resources.
Practice: Deadlocks
What are the four necessary conditions for a deadlock?
How does deadlock prevention differ from deadlock avoidance?
Can a system with only one resource of each type deadlock? Explain.
1. Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait.
2. Prevention ensures at least one condition never occurs. Avoidance uses the Banker's Algorithm to check for safe states before allocating resources.
3. Yes β if each process holds one resource and waits for another held by another process, creating a circular wait, a deadlock can occur.
08
File System Management
A file system organizes and stores data on storage devices. It provides a logical way to create, read, write, and delete files.
Files and Directories
File β A named collection of related data stored on disk
Directory β A container that holds files and other directories (folders)
Path β The location of a file in the directory tree (absolute or relative)
Metadata β File attributes like size, permissions, timestamps, owner
Contiguous Allocation β Each file occupies a contiguous block of disk space. Fast access but causes external fragmentation.
Linked Allocation β Each file is a linked list of disk blocks. No fragmentation but slow random access.
Indexed Allocation β An index block contains pointers to all data blocks. Supports direct access with minimal overhead.
Method
Fragmentation
Random Access
Disk Util
Contiguous
External
Fast
Low
Linked
None
Slow
High
Indexed
Minor
Fast
High
π‘
Modern file systems like ext4 (Linux), NTFS (Windows), and APFS (macOS) use hybrid approaches combining indexed allocation with extents for efficiency.
09
Input/Output Management
I/O Management handles communication between the system and peripheral devices like keyboards, mice, disks, printers, and network interfaces.
I/O Hardware
Device Controller β Electronic component that manages a specific device
I/O Port β Communication channel between CPU and device
Interrupts β Signals sent by devices to get CPU attention
DMA (Direct Memory Access) β Allows devices to transfer data directly to/from memory without CPU involvement
Device Drivers β Low-level code that communicates with device controllers
Disk Scheduling Algorithms
When multiple I/O requests are pending, the OS uses scheduling to minimize seek time:
FCFS β Serves requests in arrival order
SSTF (Shortest Seek Time First) β Serves the closest request first
SCAN (Elevator) β Disk arm moves in one direction, servicing requests, then reverses
C-SCAN β Like SCAN but only services requests in one direction
β
Spooling (Simultaneous Peripheral Operation On-Line) is used for devices like printers where multiple jobs queue up. The OS writes output to disk first, then sends to the printer one job at a time.
10
Security & Protection Basics
Security protects system resources from unauthorized access, malware, and attacks. Protection controls how processes access resources.
Authentication
Verifying the identity of a user or process. Common methods:
Passwords β Knowledge-based (what you know)
Biometrics β Fingerprint, face, iris (what you are)
Two-Factor Auth (2FA) β Combines password with a code (what you have)
Kerberos β Network authentication protocol using tickets
Execute (x) β Run as program or traverse directory
π‘οΈ
The principle of least privilege states that users and processes should have only the minimum permissions needed to perform their tasks. This limits damage from bugs or attacks.
11
Practice Quiz
Test your knowledge of Operating Systems with these practice questions covering all topics.
Quiz Questions
What is the primary role of an Operating System?
Which type of OS guarantees task completion within strict time constraints?
Name three core functions of an Operating System.
What is the difference between a process and a program?
Which CPU scheduling algorithm can cause the convoy effect?
What technique allows running programs larger than physical RAM?
What are the four conditions required for a deadlock?
Which file allocation method provides the fastest random access?
What does DMA stand for and why is it important?
What is the principle of least privilege?
1. To manage hardware resources and provide services for application programs.
2. Real-Time OS (RTOS).
3. Process Management, Memory Management, File System Management (also I/O Management, Security).
4. A program is a static set of instructions on disk. A process is a program in execution with its own memory, registers, and state.