Operating Systems Interview Questions
• Images marked with ★ are AI-generated.
Why is an operating system important?
The operating system is a crucial and indispensable component of a computer without which the system is practically unusable.
Key Roles:
Interface/Bridge:
Service Provider:
Resource Manager:
Without an OS:
What is the primary function of an operating system? What types of operating systems exist?
Primary Function:
The fundamental objective of an operating system is to run user programs and to simplify user interaction with computers while facilitating application execution. It is specifically designed to enhance system performance by managing all computational activities, overseeing memory management, process control, and the operation of all hardware and software components.
Types of Operating Systems:
Batched OS:
Multi-Programmed OS:
Time-Sharing OS:
Distributed OS:
Real-Time OS (RTOS):
Can you explain the main role of an operating system?
An operating system serves as a mediator between the computer user and the hardware.
Main Roles:
User Interface:
Hardware Management:
Process Management:
Memory Management:
Security and Protection:
File System Management:
What does RAID mean in the context of operating systems? What are the different RAID levels?
RAID (Redundant Array of Independent Disks) is a technology that stores data across multiple hard disks, acting as a data storage virtualization method. It balances data protection, system performance, and storage capacity.
Main Aim:
RAID Levels:
RAID 0 — Striping:
RAID 1 — Mirroring:
RAID 2 — Error-Correcting Codes:
RAID 3 — Bit-Interleaved Parity:
RAID 4 — Block-Interleaved Parity:
RAID 5 — Distributed Parity:
RAID 6 — Double Parity:

What is meant by GUI?
GUI (Graphical User Interface) is a type of interface that enables users to interact with the operating system through graphical elements such as icons, buttons, windows, and menus.
Key Characteristics:
Components of a GUI:
Examples:
GUI vs CLI:
What is a pipe in operating systems, and when is it used?
A pipe is a connection mechanism between two or more related processes, used for inter-process communication (IPC) via message passing.
How it Works:
Types of Pipes:
Anonymous (Unnamed) Pipes:
Named Pipes (FIFOs):
When Pipes Are Used:
Characteristics:
What types of operations can be performed on a semaphore?
There are two fundamental atomic operations that can be performed on semaphores:
Wait() — also called P() or Down():
Signal() — also called V() or Up():
Key Properties:
Example:
```
Wait(semaphore S):
S.value = S.value - 1
if S.value < 0: block this process
Signal(semaphore S):
S.value = S.value + 1
if S.value <= 0: unblock a waiting process
```
What is a bootstrap program in an operating system?
A bootstrap program is the initial program that runs during system startup. It is the first code executed whenever the computer powers on.
Key Functions:
Bootstrap Process:
1. Computer is powered on.
2. CPU executes the bootstrap program from ROM/BIOS/UEFI.
3. Bootstrap performs hardware diagnostics (POST — Power-On Self Test).
4. Bootstrap locates the OS kernel on the storage device.
5. Kernel is loaded into main memory.
6. Kernel begins execution and initializes the system.
Where It Is Stored:
Key Point:

Can you describe the concept of demand paging?
Demand paging is a technique where pages are loaded into memory only when they are needed. It is widely used in virtual memory systems.
How Demand Paging Works:
1. A page is referenced during execution.
2. System attempts to access the page.
3. If the page is already in memory → normal processing continues.
4. If the page is not in memory → a page-fault trap is triggered.
5. System checks if the reference is valid — if invalid, the process terminates.
6. If valid, the required page is brought from secondary storage (disk) into main memory.
7. The interrupted instruction restarts after the page has been loaded.
Key Concept — Lazy Loading:
Benefits:
Page Fault:
What does RTOS stand for?
RTOS stands for Real-Time Operating System.
A Real-Time Operating System is designed for applications requiring data processing within strict time constraints. It excels at executing tasks that must complete within a short, fixed time.
Key Characteristics:
Types of RTOS:
Hard Real-Time:
Firm Real-Time:
Soft Real-Time:
Common Use Cases:
Examples of RTOS: PSOS, VRTX, VxWorks, FreeRTOS, QNX.
What is a process, and what is a process table?
Process:
A process is an executing instance of a program such as a web browser or command prompt. It is a program in active execution managed by the operating system.
Key Characteristics:
Process Table:
The OS maintains a process table — a data structure listing all active processes alongside their:
Purpose of Process Table:
Example:
Define a process. What are the various states a process can be in?
Process Definition:
A process is a program in execution managed by the OS. When loaded into memory, it consists of four sections: stack, heap, text, and data.
Processes are categorized into:
Process States:
New:
Running:
Waiting (Blocked):
Ready:
Terminate (Exit):
State Transitions:

What are the different states of a process?
Processes exist in three primary states at any given time, with additional transitional states:
Running:
Ready:
Waiting (Blocked):
Additional States:
New:
Terminated:
Queue Management:

What is a thread?
A thread is a single sequence of execution within a process. Threads are lightweight processes that enhance parallelism.
Key Characteristics:
Real-World Examples:
Benefits of Threads:
Types of Threads:
How is a thread defined in an operating system?
A thread is an execution path comprising a program counter, thread ID, stack, and registers inside a process.
Formal Definition:
What Threads Share (within the same process):
What Threads Have Individually:
Advantages of Threads:
Thread ID:
What are the different sections within a process?
A process is composed of four main sections when loaded into memory:
Stack:
Heap:
Data Section:
- Initialized data — variables with initial values.
- Uninitialized data (BSS) — variables without initial values.
Code / Text Section:
Memory Layout (top to bottom):

How do processes and threads differ?
Process vs Thread — Key Differences:
Execution Unit:
Memory Usage:
Communication:
Context Switch:
Creation Overhead:
Isolation:
Example:

What advantages does multithreaded programming offer?
Multithreaded programming offers several significant advantages:
Enhanced Responsiveness:
Resource Sharing:
Economy:
Multiprocessor Utilization:
Improved Performance:
Scalability:
What does FCFS stand for?
FCFS stands for First Come First Serve.
It is one of the simplest CPU scheduling algorithms that executes processes in the exact order they arrive in the ready queue.
Key Characteristics:
How it Works:
1. Processes enter the ready queue in arrival order.
2. The CPU picks the first process in the queue.
3. That process runs to completion.
4. The next process in the queue is then selected.
Advantages:
Disadvantages:
Example:
What is reentrancy?
Reentrancy refers to the property of a function that allows it to be used simultaneously by multiple clients sharing a single program copy.
It relates mainly to OS code and does not directly deal with concurrency or thread safety.
Key Features of a Reentrant Function:
No Self-Modification:
Separate Local Data:
Why Reentrancy Matters:
Reentrant vs Thread-Safe:
Example:
What is a scheduling algorithm? Can you name different types?
A scheduling algorithm optimizes CPU utilization and minimizes waiting time by deciding which process gets resource allocation and when. It ensures fairness and reduces resource starvation among competing tasks.
Purpose:
Types of Scheduling Algorithms:
First-Come First-Served (FCFS):
Shortest Job First (SJF):
Priority Scheduling:
Shortest Remaining Time (SRT):
Round Robin (RR):
Multilevel Queue Scheduling:
Multilevel Feedback Queue:
What is the Round Robin (RR) scheduling algorithm?
Round Robin (RR) scheduling assigns each process a fixed time slot called a quantum and cycles through all jobs fairly, giving each an equal share of CPU time.
How it Works:
1. All processes are placed in a circular ready queue.
2. The CPU executes each process for a fixed time quantum (e.g., 10ms).
3. If the process finishes within the quantum → it leaves the queue.
4. If it doesn't finish → it is interrupted and placed at the end of the queue.
5. The next process in the queue gets the CPU.
Key Features:
Quantum Size Impact:
Advantages:
Disadvantage:
Briefly explain the First-Come, First-Served (FCFS) scheduling.
FCFS (First Come First Served) scheduling allocates CPU to jobs in their arrival order.
Key Characteristics:
How It Works:
1. Processes enter the ready queue in order of arrival.
2. CPU picks the first process in the queue.
3. Process runs to completion without interruption.
4. Next process in queue is then selected.
Example:
| Process | Arrival | Burst Time | Wait Time |
|---|---|---|---|
| P1 | 0ms | 10ms | 0ms |
| P2 | 1ms | 2ms | 9ms |
| P3 | 2ms | 3ms | 10ms |
Advantages:
Disadvantages:
What is the main goal of multiprogramming?
Multiprogramming allows multiple programs to run on a single processor by managing CPU and memory usage efficiently.
Main Goal:
How It Works:
Benefits:
Example:
Difference from Multitasking:
What defines a time-sharing system?
A time-sharing system enables multiple users to access and share a system's resources simultaneously from different locations.
Key Definition:
How It Works:
1. Multiple users connect to the system simultaneously.
2. The OS divides CPU time into small time slots (typically milliseconds).
3. Each user/process gets a time slot in turn.
4. Switching is so fast that each user feels they have dedicated access.
Key Characteristics:
Benefits:
Example:
What is preemptive multitasking?
Preemptive multitasking is a scheduling method where the OS can interrupt and pause a currently running process to allocate CPU time to another process.
Key Concept:
How It Works:
1. Process A is running on the CPU.
2. A timer interrupt fires (time quantum expires) OR a higher-priority process becomes ready.
3. OS saves the state of Process A (context switch).
4. OS assigns CPU to Process B.
5. Process A resumes later when selected again.
Why It's Used:
Contrast with Cooperative Multitasking:
Modern Usage:
What are the various scheduling algorithms?
The main CPU scheduling algorithms used in operating systems are:
First Come First Serve (FCFS):
Shortest Job First (SJF):
Shortest Remaining Time First (SRTF):
Priority Scheduling:
Round Robin (RR):
Multilevel Queue Scheduling:
Multilevel Feedback Queue Scheduling:
What is virtual memory?
Virtual memory is a memory management technique that offers an idealized abstraction of the storage resources available on a machine.
Core Concept:
How It Works:
Benefits:
Key Concepts:
Example:
Could you explain virtual memory in detail?
Virtual memory is a memory management approach that provides an "idealized abstraction of the storage resources actually available on a machine", thereby "creating the illusion for users of a very large memory."
Detailed Explanation:
Address Spaces:
Page Table:
Page Fault Handling:
1. Process accesses a virtual address.
2. MMU checks the page table.
3. If page is not in RAM → page fault interrupt.
4. OS finds the page on disk (swap space).
5. OS loads the page into a free frame in RAM.
6. Page table is updated.
7. Instruction restarts.
Demand Paging:
Page Replacement Algorithms:
Thrashing:

How do paging and segmentation differ?
Paging vs Segmentation — Key Differences:
Memory Division:
Programmer Visibility:
Fragmentation:
Primary Purpose:
Address Structure:
Size:
Modern Systems:
What is the fundamental function of paging?
The fundamental function of paging is to divide a process into pages and physical memory into frames, then map pages to frames to enable non-contiguous storage of processes in memory.
Core Mechanism:
Pages:
Frames:
Page Table:
Key Benefits:
Eliminates External Fragmentation:
Non-Contiguous Storage:
Simplifies Memory Allocation:
Enables Virtual Memory:
Internal Fragmentation:
What does fragmentation mean?
Fragmentation describes the inefficient use of storage space, which decreases capacity or system performance. It happens when memory is broken into scattered, unusable pieces.
Types of Fragmentation:
Internal Fragmentation:
External Fragmentation:
Solutions:
For Internal Fragmentation:
For External Fragmentation:
What are overlays?
Overlays are a programming method that allows a process to be larger than its allocated memory.
Core Concept:
How Overlays Work:
1. Program is divided into logical sections that don't need to be in memory simultaneously.
2. A root segment (always in memory) manages which overlays to load.
3. When a function in an unloaded overlay is called, the overlay is loaded from disk.
4. It overwrites a previously loaded overlay that is no longer needed.
Historical Context:
Difference from Virtual Memory:
Example:
How does swapping improve memory management?
Swapping is a memory management technique where a process is temporarily moved from main memory (RAM) to secondary storage (disk) and later brought back for execution.
How Swapping Works:
1. Main memory becomes full with active processes.
2. OS selects a process to swap out (moves it to disk swap space).
3. Memory is freed for other processes to use.
4. The swapped-out process is stored on disk in a swap file or partition.
5. When the process needs to run again, it is swapped back into RAM.
How It Improves Memory Management:
Increases Multiprogramming Level:
Better Memory Utilization:
Supports Virtual Memory:
Limitations:

What is the primary difference between logical and physical address space?
Logical vs Physical Address Space — Key Differences:
Logical Address (Virtual Address):
Physical Address:
How They Relate:
Why the Distinction Matters:
Example:
What is demand paging, and how does it operate?
Demand paging is a virtual memory technique where pages are loaded into memory only when required during execution — not all at once when the program starts.
How Demand Paging Operates:
1. Page is referenced during program execution.
2. System checks if the page is in memory:
- Yes (Page Hit) → execution continues normally.
- No (Page Miss) → a page fault occurs.
3. OS verifies if the reference is valid:
- Invalid → process is terminated (segmentation fault).
- Valid → page needs to be loaded.
4. OS finds the page on secondary storage (disk).
5. OS loads the page into a free frame in RAM.
6. Page table is updated to reflect new location.
7. Instruction that caused the fault restarts.
Key Concept — Lazy Loading:
Benefits:
Page Fault Rate:
What is a semaphore in an operating system, and why is it used?
A semaphore is a synchronization mechanism used to control access to shared resources by multiple processes concurrently.
Definition:
Types of Semaphores:
Binary Semaphore (Mutex):
Counting Semaphore:
Why Semaphores Are Used:
Mutual Exclusion:
Process Synchronization:
Prevents Race Conditions:
Resource Management:
Example:
What benefits do semaphores provide?
Semaphores provide several significant advantages in operating systems:
Platform Independence:
Simple Implementation:
Easier Correctness Verification:
Multiple Critical Section Management:
Simultaneous Resource Acquisition:
No Busy Waiting (Blocking Semaphores):
Flexibility:
What conditions must be met for a deadlock to occur in a system?
For a deadlock to occur, all four of the following conditions must hold simultaneously (Coffman's conditions):
1. Mutual Exclusion:
2. Hold and Wait:
3. No Preemption:
4. Circular Wait:
Prevention:

What is a deadlock in operating systems, and what are its necessary conditions?
Deadlock is a scenario where a set of processes are blocked as each holds resources and waits for resources held by others. Multiple processes try to execute simultaneously but end up waiting for each other indefinitely due to dependencies.
Analogy:
Common in multiprocessing systems where multiple processes compete for shared resources.
Necessary Deadlock Conditions (all four must hold):
Mutual Exclusion:
Hold and Wait:
No Preemption:
Circular Wait (Resource Wait):
Deadlock Handling Strategies:
Can you define deadlock?
Deadlock occurs when two or more processes are waiting indefinitely for each other to finish, and none of them ever does.
Simple Definition:
Classic Analogy:
In Operating Systems:
Key Characteristics:
Example:
```
Process A: lock(R1) → wait for R2
Process B: lock(R2) → wait for R1
→ DEADLOCK: Both waiting forever
```
Resolution Methods:
What is Peterson's solution or approach?
Peterson's solution is a concurrency algorithm used to synchronize two processes, ensuring mutual exclusion for a shared resource or critical section.
How It Works:
Uses two variables to manage access:
Boolean flag array (size 2):
Integer variable "turn":
Algorithm for Process i:
```
flag[i] = true; // I want to enter
turn = j; // Give turn to other process
while (flag[j] && turn == j); // Wait if other wants and it's their turn
// CRITICAL SECTION
flag[i] = false; // I'm done
```
Properties Satisfied:
Limitations:
What are the disadvantages of using semaphores?
While semaphores are useful synchronization tools, they have several notable drawbacks:
Priority Inversion:
Usage by Convention Only:
Tracking Overhead:
Deadlock Risk:
Difficult to Debug:
No Built-in Ownership:
What is the kernel, and what are its main functions?
The kernel is the core component of an operating system responsible for managing and controlling all system and hardware operations.
Key Characteristics:
Main Functions:
Resource Management:
Hardware-Software Interaction:
Memory Management:
Process Management:
Device Management:
CPU Scheduling:
What different types of kernels exist?
The main types of kernels used in operating systems are:
Monolithic Kernel:
Microkernel:
Hybrid Kernel:
Exokernel:
Nano Kernel:
Modern Trend:
How do microkernels differ from monolithic kernels?
Monolithic Kernel vs Microkernel — Key Differences:
Size:
Service Location:
Performance:
Security:
Maintainability:
Examples:
Modern Note:

What is context switching?
Context switching is the procedure of saving the state of one process and loading the state of another, allowing the CPU to switch between processes.
What Gets Saved/Restored (Process Context):
How Context Switching Works:
1. Interrupt or system call triggers a context switch.
2. OS saves the current process's context into its PCB (Process Control Block).
3. OS selects the next process to run (via scheduling algorithm).
4. OS loads the saved context of the selected process from its PCB.
5. CPU resumes execution of the new process.
Key Characteristics:
Overhead:

What is Belady's Anomaly?
Belady's Anomaly is an occurrence where increasing the number of frames (page slots) in memory causes an increase in page faults instead of the expected decrease.
Background:
When It Occurs:
Example:
Why It Happens:
Algorithms That Don't Suffer from Belady's Anomaly:
What is spooling in operating systems?
Spooling (Simultaneous Peripheral Operations OnLine) is the process of placing data from various I/O jobs into a buffer — a special area in memory or disk accessible to I/O devices.
Core Concept:
How Spooling Works:
1. Application generates output (e.g., print job).
2. Output is written to the spool buffer on disk — not directly to printer.
3. CPU is immediately free to continue other tasks.
4. Spooler daemon manages sending data from buffer to the slow device.
5. Printer processes data at its own pace from the spool.
Common Examples:
Print Spooling:
Email Spooling:
Benefits:
What do starvation and aging mean in the context of operating systems?
Starvation and Aging are related concepts in CPU scheduling dealing with process fairness.