OS

OS

Top Interview Questions

About OS

 

Operating System (OS) – Detailed Overview

An Operating System (OS) is system software that acts as an interface between computer hardware and the user. It manages hardware resources, provides common services for computer programs, and ensures that applications execute efficiently and securely. Without an operating system, a computer would be unable to perform meaningful tasks, as users and applications would have no direct way to interact with hardware components such as the CPU, memory, disk, and input/output devices.

In simple terms, the operating system is the backbone of a computer system, responsible for controlling and coordinating all activities within the system.


Objectives of an Operating System

The primary objectives of an operating system are:

  1. Convenience – Makes the computer easier to use.

  2. Efficiency – Utilizes hardware resources effectively.

  3. Resource Management – Allocates and deallocates resources such as CPU, memory, and devices.

  4. Security and Protection – Protects data and programs from unauthorized access.

  5. Reliability – Ensures consistent system operation even in the presence of errors.


Functions of an Operating System

1. Process Management

A process is a program in execution. The operating system is responsible for:

  • Creating and terminating processes

  • Scheduling processes on the CPU

  • Managing process synchronization and communication

  • Handling deadlocks and starvation

Modern operating systems support multitasking, allowing multiple processes to run concurrently by rapidly switching the CPU between tasks.


2. Memory Management

Memory management involves controlling and coordinating computer memory. The OS:

  • Keeps track of memory usage

  • Allocates memory to processes when required

  • Deallocates memory when processes terminate

  • Supports techniques like paging, segmentation, and virtual memory

Virtual memory allows the system to run programs larger than physical memory by using disk space as an extension of RAM.


3. File System Management

The operating system manages data stored on secondary storage devices such as hard disks and SSDs. Responsibilities include:

  • Creating, reading, writing, and deleting files

  • Organizing files into directories

  • Maintaining file metadata (size, permissions, timestamps)

  • Enforcing file access permissions

Popular file systems include NTFS, FAT32, ext4, and APFS.


4. Device Management

Device management ensures smooth interaction between hardware devices and software. The OS:

  • Uses device drivers to communicate with hardware

  • Handles input/output operations

  • Allocates devices to processes

  • Manages buffering, caching, and spooling

Examples of devices include printers, keyboards, mice, scanners, and network cards.


5. CPU Scheduling

CPU scheduling determines which process gets CPU time and for how long. Scheduling algorithms include:

  • First Come First Serve (FCFS)

  • Shortest Job First (SJF)

  • Priority Scheduling

  • Round Robin

Efficient CPU scheduling improves system throughput and responsiveness.


6. Security and Protection

The OS protects system resources and user data by:

  • Authentication (user login)

  • Authorization (access control)

  • Encryption

  • Process isolation

Security mechanisms prevent malicious programs from damaging the system or accessing sensitive data.


7. User Interface

The operating system provides an interface for user interaction:

  • Command Line Interface (CLI) – Text-based interaction (e.g., Linux terminal)

  • Graphical User Interface (GUI) – Visual interaction using windows, icons, and menus (e.g., Windows, macOS)


Types of Operating Systems

1. Batch Operating System

In batch systems, jobs are collected and processed in batches without user interaction. These systems were common in early computers.

2. Time-Sharing Operating System

Time-sharing systems allow multiple users to interact with the computer simultaneously by sharing CPU time. Example: UNIX.

3. Distributed Operating System

A distributed OS manages a group of computers and makes them appear as a single system. Resources are shared across machines.

4. Network Operating System

This OS runs on a server and manages network resources, users, and security. Example: Windows Server.

5. Real-Time Operating System (RTOS)

RTOS is designed for systems requiring strict timing constraints, such as medical equipment, robotics, and aerospace systems.

6. Mobile Operating System

Designed for smartphones and tablets. Examples include Android and iOS.


Components of an Operating System

1. Kernel

The kernel is the core of the operating system. It manages:

  • CPU scheduling

  • Memory management

  • Device communication

  • System calls

Types of kernels:

  • Monolithic Kernel

  • Microkernel

  • Hybrid Kernel


2. Shell

The shell is an interface between the user and the kernel. It interprets user commands and executes them.


3. System Utilities

These are programs that perform maintenance tasks such as disk cleanup, file compression, and system monitoring.


Operating System Services

The OS provides several services to programs:

  • Program execution

  • I/O operations

  • File manipulation

  • Error detection

  • Resource allocation

  • Accounting and logging


Examples of Popular Operating Systems

  • Windows – Widely used in personal computers

  • Linux – Open-source and popular in servers and embedded systems

  • macOS – Used in Apple computers

  • UNIX – Powerful multi-user OS used in enterprises

  • Android – Mobile OS based on Linux

  • iOS – Apple’s mobile operating system


Importance of Operating Systems

The operating system plays a crucial role in:

  • Enabling hardware usability

  • Improving system performance

  • Providing security

  • Supporting application development

  • Enabling multitasking and multi-user environments

Without an operating system, a computer is just a collection of hardware components with no coordination.

Fresher Interview Questions

 

1. What is an Operating System (OS)?

Answer:
An Operating System is system software that acts as an interface between computer hardware and the user. It manages hardware resources, provides a platform for applications, and ensures smooth execution of processes. Examples: Windows, Linux, macOS, Android.


2. What are the main functions of an OS?

Answer:

  1. Process Management – Managing process creation, execution, and termination.

  2. Memory Management – Allocating and deallocating memory efficiently.

  3. File System Management – Managing files, directories, and storage.

  4. Device Management – Controlling input/output devices.

  5. Security and Access Control – Protecting data and resources.

  6. User Interface Management – Providing CLI or GUI for user interaction.


3. What are the types of operating systems?

Answer:

  1. Batch OS – Executes jobs in batches; e.g., early IBM systems.

  2. Time-Sharing OS – Allows multiple users to share CPU simultaneously.

  3. Distributed OS – Manages multiple computers as a single system; e.g., Amoeba.

  4. Real-Time OS (RTOS) – Provides immediate response; e.g., VxWorks.

  5. Network OS – Supports networking and resource sharing; e.g., Novell NetWare.

  6. Mobile OS – Optimized for mobile devices; e.g., Android, iOS.


4. What is a process?

Answer:
A process is a program in execution, which includes the program code, current activity, CPU registers, memory, and I/O status. It is the basic unit of CPU utilization.


5. What is the difference between a process and a thread?

Feature Process Thread
Definition Program in execution Lightweight process inside a process
Memory Has its own memory Shares memory with other threads in the same process
Creation Higher overhead Lower overhead
Communication IPC needed Direct memory sharing

6. What are the states of a process?

Answer:

  1. New – Process is being created.

  2. Ready – Process is waiting to be assigned to CPU.

  3. Running – Process is executing on CPU.

  4. Waiting/Blocked – Process waiting for an event or I/O.

  5. Terminated – Process has finished execution.


7. What is a thread?

Answer:
A thread is the smallest unit of CPU execution within a process. Threads share the process’s memory but have their own program counter, stack, and registers.


8. What is multithreading?

Answer:
Multithreading allows multiple threads to run concurrently within the same process, improving CPU utilization and application responsiveness.


9. What is a deadlock?

Answer:
A deadlock is a situation where a set of processes are waiting for each other indefinitely, and none of them can proceed.


10. What are the necessary conditions for a deadlock?

Answer:

  1. Mutual Exclusion – At least one resource must be held in a non-shareable mode.

  2. Hold and Wait – A process holding a resource is waiting for another resource.

  3. No Preemption – Resources cannot be forcibly taken from a process.

  4. Circular Wait – A circular chain of processes exists, each waiting for a resource held by the next.


11. What is the difference between preemptive and non-preemptive scheduling?

Feature Preemptive Non-Preemptive
CPU allocation Can forcibly take CPU from a process Process releases CPU voluntarily
Example Round Robin First-Come-First-Served (FCFS)

12. Explain CPU scheduling algorithms.

Answer:

  1. FCFS (First-Come-First-Served) – Processes are scheduled in arrival order.

  2. SJF (Shortest Job First) – Process with shortest burst time is executed first.

  3. Priority Scheduling – Process with highest priority is executed first.

  4. Round Robin (RR) – Processes are executed in a cyclic order with time quantum.

  5. Multilevel Queue Scheduling – Processes are divided into queues based on priority or type.


13. What is context switching?

Answer:
Context switching is the process of storing the state of a currently running process and loading the state of the next process to execute, allowing CPU to switch between processes.


14. What is virtual memory?

Answer:
Virtual memory allows a computer to use disk space as an extension of RAM, giving the illusion of more memory. Techniques include paging and segmentation.


15. What is paging?

Answer:
Paging is a memory management scheme where physical memory is divided into fixed-size blocks called frames, and logical memory into pages. Pages are mapped to frames using a page table.


16. What is segmentation?

Answer:
Segmentation divides a program into variable-sized segments based on logical units like functions, objects, or arrays, improving modularity and protection.


17. What is the difference between paging and segmentation?

Feature Paging Segmentation
Size Fixed-size Variable-size
Concept Divides memory into pages Divides memory into logical segments
Addressing Page number + offset Segment number + offset
External fragmentation No Possible

18. What is thrashing?

Answer:
Thrashing occurs when a system spends more time swapping pages in and out of memory than executing processes, leading to low CPU utilization.


19. What is a file system?

Answer:
A file system is a method used by an OS to store, organize, and manage files on storage devices. Examples: FAT32, NTFS, ext4.


20. What are the types of file access methods?

  1. Sequential Access – Read/write data in order.

  2. Direct/Random Access – Access data at any position.


21. What is a semaphore?

Answer:
A semaphore is a synchronization tool used to control access to shared resources by multiple processes. Types:

  1. Binary Semaphore – Values 0 or 1.

  2. Counting Semaphore – Integer values to control multiple resources.


22. What is a mutex?

Answer:
A mutex is a locking mechanism to ensure that only one thread accesses a shared resource at a time.


23. Difference between semaphore and mutex

Feature Semaphore Mutex
Value Can be >1 Binary (0/1)
Ownership No owner Owned by a thread
Use Multiple threads Single thread access

24. What is starvation in OS?

Answer:
Starvation occurs when a process waits indefinitely because higher-priority processes keep getting CPU.


25. What is aging in OS?

Answer:
Aging is a technique to gradually increase the priority of a process that waits in the ready queue for a long time, preventing starvation.


26. What is a kernel?

Answer:
The kernel is the core component of an OS, responsible for process management, memory management, device management, and system calls.


27. Types of OS kernels

  1. Monolithic Kernel – Entire OS runs in kernel mode; fast but less secure.

  2. Microkernel – Only essential services run in kernel; modular and secure.

  3. Hybrid Kernel – Combination of monolithic and microkernel.


28. What is an interrupt?

Answer:
An interrupt is a signal to the CPU indicating an event that needs immediate attention. Types:

  1. Hardware Interrupt – Generated by hardware (keyboard, mouse).

  2. Software Interrupt – Generated by software or system calls.


29. What is spooling?

Answer:
Spooling (Simultaneous Peripheral Operations On-Line) is a process where data is temporarily held in a buffer before sending to an output device like a printer.


30. What is an OS shell?

Answer:
A shell is a user interface (CLI or GUI) that allows users to interact with the OS and execute commands.


31. What is memory leak?

Answer:
A memory leak occurs when a program allocates memory but fails to release it, leading to wasted memory and potential system crash.


32. Difference between logical and physical address

Feature Logical Address Physical Address
Definition Generated by CPU Actual location in RAM
View Process view Hardware view
Translation Needs MMU No translation

33. What is I/O management?

Answer:
I/O management coordinates and controls input/output operations, using techniques like buffering, caching, spooling, and device drivers.


34. What is DMA (Direct Memory Access)?

Answer:
DMA allows devices to transfer data directly to/from memory without CPU intervention, increasing efficiency.


35. What is a boot loader?

Answer:
A boot loader is a program that loads the OS into memory during system startup.


36. What is paging vs segmentation vs virtual memory?

  • Paging – Fixed-size memory blocks, no external fragmentation.

  • Segmentation – Variable-size, logical division, possible fragmentation.

  • Virtual Memory – Uses disk as RAM extension; supports paging and segmentation.


37. What is the difference between OS and application software?

Feature OS Application Software
Purpose Manage hardware and resources Solve user-specific problems
Examples Windows, Linux MS Office, Photoshop
Dependency Runs independently Depends on OS

38. What is a real-time OS (RTOS)?

Answer:
RTOS guarantees task execution within a fixed time frame, used in embedded systems, robotics, and critical systems. Types: Hard RTOS and Soft RTOS.


39. What is a page fault?

Answer:
A page fault occurs when a program accesses a page not currently in physical memory, prompting the OS to fetch it from disk.


40. Difference between blocking and non-blocking I/O

Feature Blocking I/O Non-blocking I/O
CPU Wait Waits until I/O completes CPU continues execution
Efficiency Less efficient More efficient

41. What is a file descriptor?

Answer:
A file descriptor is an integer representing an open file or I/O resource used by a process in Unix/Linux systems.


42. Difference between hard link and soft link

Feature Hard Link Soft Link (Symbolic)
Reference Points to inode Points to file path
Across File Systems Not allowed Allowed
Deletion effect Original file remains Broken if target deleted

43. What is swapping?

Answer:
Swapping is moving a process from main memory to disk and back to free up RAM for other processes.


44. What is thrashing?

Answer:
When the OS spends most time swapping pages in/out due to insufficient memory, reducing CPU efficiency.


45. What is the difference between multitasking and multiprocessing?

Feature Multitasking Multiprocessing
CPU Single CPU Multiple CPUs
Execution Interleaved Parallel
Example Windows Linux SMP

46. What is a race condition?

Answer:
A race condition occurs when multiple processes/threads access shared data simultaneously, leading to unpredictable results.


47. How to prevent race conditions?

Answer:
Using synchronization mechanisms like:

  • Mutexes

  • Semaphores

  • Monitors

  • Locks


48. Difference between user mode and kernel mode

Feature User Mode Kernel Mode
Privileges Limited Full
Execution Cannot access hardware directly Can access hardware and memory
Example Application programs OS kernel

49. What is a system call?

Answer:
A system call is an API provided by the OS for applications to request services like file I/O, process control, and communication.


50. What is a boot process?

Answer:
Steps during system startup:

  1. Power-On Self Test (POST)

  2. Boot loader loads OS

  3. Kernel initialization

  4. System and user processes start


51. What is fragmentation?

Answer:

  • Internal Fragmentation – Wasted memory inside allocated blocks.

  • External Fragmentation – Wasted memory outside allocated blocks.


52. What is a swap space?

Answer:
Swap space is disk space used to store inactive pages from RAM to free memory.


53. Difference between logical and physical memory

  • Logical memory: Seen by the process.

  • Physical memory: Actual RAM used by OS.


54. What is a shell vs kernel?

  • Kernel – Core OS, manages hardware.

  • Shell – Interface for user to interact with OS.


55. Explain process synchronization

Answer:
Ensures orderly execution of processes to prevent conflicts when sharing resources. Tools: semaphores, mutexes, monitors, critical sections.


56. Difference between monolithic and microkernel

Feature Monolithic Microkernel
Structure All services in kernel Minimal kernel + user-space services
Performance Fast Slightly slower
Security Less secure More secure

 

Experienced Interview Questions

 

1. What is an Operating System (OS)?

Answer:
An Operating System is system software that acts as an interface between hardware and users/applications. It manages hardware resources like CPU, memory, I/O devices, and provides services for application programs.

Example: Windows, Linux, macOS, Android, iOS.

Key Points:

  • Resource management

  • Process management

  • Memory management

  • File system management

  • Security & user management


2. What are the main types of Operating Systems?

Answer:

  1. Batch OS: Executes jobs in batches; no interaction with users (e.g., IBM Mainframe OS).

  2. Time-Sharing OS: Allows multiple users to share CPU time simultaneously (e.g., Unix).

  3. Distributed OS: Manages a group of independent computers and makes them appear as a single system (e.g., Amoeba OS).

  4. Real-Time OS (RTOS): Used where timing is critical; can be hard or soft real-time (e.g., VxWorks).

  5. Network OS: Provides services to computers connected in a network (e.g., Novell NetWare).

  6. Mobile OS: Optimized for smartphones/tablets (e.g., Android, iOS).


3. Explain the difference between Kernel Mode and User Mode.

Answer:

Feature Kernel Mode User Mode
Privilege Level High (full access to hardware) Low (restricted access)
Access Direct access to hardware & memory Access via system calls only
Examples OS Kernel, Device Drivers Applications, User Programs
Risk Errors can crash OS Errors affect only the program

Scenario: When a user program requests disk access, it triggers a system call, switching from user mode to kernel mode.


4. What is a process?

Answer:
A process is a program in execution. It includes:

  • Program Counter (PC)

  • Stack (for function calls & local variables)

  • Data Section

  • Heap (for dynamic memory)

States of a process: New → Ready → Running → Waiting → Terminated

Example: When you open Chrome, each tab is a separate process.


5. What is the difference between a process and a thread?

Answer:

Feature Process Thread
Memory Separate memory space Shares memory within a process
Overhead High (context switching) Low
Communication Inter-process Communication Direct (shared memory)
Example Chrome Browser Tabs Threads within a Chrome tab

Scenario: Multi-threaded server handles thousands of client requests efficiently using threads.


6. Explain Process Scheduling.

Answer:
Process Scheduling is the method by which the OS decides which process runs next. It improves CPU utilization, throughput, and response time.

Types of Scheduling:

  1. Long-term: Decides which jobs to admit to the ready queue.

  2. Medium-term: Suspends/resumes processes to balance load.

  3. Short-term: CPU scheduler decides which process runs next.

Algorithms:

  • FCFS (First Come First Serve) – Simple but can cause convoy effect.

  • SJF (Shortest Job First) – Minimizes waiting time; risk of starvation.

  • Priority Scheduling – Uses priority; high risk of starvation.

  • Round Robin (RR) – Fair, uses time quantum; good for time-sharing.

  • Multilevel Queue/Feedback Queue – Combines multiple policies.


7. What is a deadlock?

Answer:
Deadlock occurs when two or more processes are waiting indefinitely for resources held by each other.

Necessary Conditions (Coffman conditions):

  1. Mutual exclusion

  2. Hold and wait

  3. No preemption

  4. Circular wait

Handling Deadlocks:

  • Prevention – Ensure at least one Coffman condition never holds.

  • Avoidance – Use algorithms like Banker’s algorithm.

  • Detection & Recovery – Detect using wait-for graph and terminate processes.

Scenario: Printer and Scanner deadlock if two processes hold one and wait for the other.


8. Explain Memory Management.

Answer:
Memory management ensures efficient allocation and deallocation of RAM.

Techniques:

  • Contiguous Allocation: Easy but causes fragmentation.

  • Paging: Breaks memory into fixed-size pages; solves external fragmentation.

  • Segmentation: Divides memory logically (code, data, stack).

  • Virtual Memory: Uses disk as an extension of RAM; allows demand paging.

Scenario: Running a 16 GB application on an 8 GB RAM system uses virtual memory with page swapping.


9. What is a Page Fault?

Answer:
Occurs when a program accesses a page not currently in RAM. The OS brings the page from disk.

Example: Accessing a large dataset that doesn’t fit in physical memory triggers page faults.

Handling:

  • Load page from disk to memory

  • Update page table

  • Resume execution


10. Explain File Systems.

Answer:
A file system manages data storage on disks. It organizes files into directories, controls access, and manages storage allocation.

Components:

  • File Control Block (FCB) – Metadata like size, type, permissions

  • Directory structure – Hierarchical (tree) or flat

  • Allocation methods: Contiguous, Linked, Indexed

Example: NTFS, ext4, FAT32.


11. Explain Context Switching.

Answer:
Context switching is saving the state of a running process and loading the state of the next scheduled process.

Overhead: CPU time is wasted during switching.

Scenario: In multitasking OS, switching between Chrome, VSCode, and Terminal.


12. What is a System Call?

Answer:
A system call is a request made by a user program to the OS to perform privileged operations.

Types:

  • Process control (fork, exit)

  • File management (open, read, write)

  • Device management (ioctl)

  • Communication (pipe, message queues)

Scenario: read() system call reads data from a file into user memory.


13. What is Inter-Process Communication (IPC)?

Answer:
IPC allows processes to exchange data.

Methods:

  • Pipes (anonymous or named)

  • Message queues

  • Shared memory

  • Semaphores

  • Sockets

Scenario: Client-server communication in a distributed application uses sockets.


14. What is a Semaphore?

Answer:
Semaphore is a synchronization primitive used to solve race conditions and coordinate processes.

Types:

  • Binary semaphore: Only 0 or 1 (like a mutex)

  • Counting semaphore: Can take non-negative integer values

Scenario: Controlling access to a printer by multiple processes.


15. Explain Critical Section Problem.

Answer:
A critical section is a part of code where shared resources are accessed.

Requirements:

  1. Mutual exclusion

  2. Progress (no process waits forever)

  3. Bounded waiting

Solution: Semaphores, Mutex, Monitors.


16. What is a Mutex?

Answer:
Mutex is a mutual exclusion object used to prevent concurrent access to a resource by multiple threads.

Scenario: Only one thread can update a bank account balance at a time.


17. Explain CPU Scheduling Algorithms in detail.

  • Already partially covered in Question 6

  • Additional advanced algorithms:

    • Multilevel Feedback Queue: Dynamically adjusts priority based on behavior.

    • Shortest Remaining Time First (SRTF): Preemptive SJF variant.

Metrics for evaluation: Turnaround time, waiting time, response time, CPU utilization.


18. What is Thrashing?

Answer:
Thrashing occurs when the OS spends more time swapping pages than executing processes, due to insufficient memory.

Solution:

  • Increase RAM

  • Use working set model

  • Limit multiprogramming degree


19. Explain the difference between Preemptive and Non-Preemptive Scheduling.

Feature Preemptive Scheduling Non-Preemptive Scheduling
CPU takeover OS can suspend running process Process runs till completion
Examples Round Robin, SJF (preemptive) FCFS, SJF (non-preemptive)
Use-case Interactive systems Batch systems

20. Explain Swap Space.

Answer:
Swap space is disk space used as virtual memory. It helps when RAM is insufficient.

Scenario: Linux often uses /swapfile or dedicated swap partition.


21. What is Paging?

Answer:
Paging is a memory management scheme that eliminates external fragmentation by dividing physical memory into fixed-size frames and logical memory into pages.

Key Points:

  • Logical addresses are divided into page number and page offset.

  • Physical memory uses frame number + offset.

  • Page tables map virtual pages to physical frames.

Scenario: A process of 50 KB is loaded into memory with 4 KB pages. OS maps 13 pages into different frames in RAM.


22. What is Segmentation?

Answer:
Segmentation divides memory into logical units like code, data, stack, or functions. Each segment has a base and limit.

Difference from Paging:

  • Paging: fixed-size, no logical meaning

  • Segmentation: variable-size, logically meaningful

Example: Code segment 10 KB, Data segment 5 KB, Stack segment 2 KB.


23. What is Virtual Memory?

Answer:
Virtual memory allows execution of programs larger than physical memory using disk space.

Techniques:

  • Demand Paging: Load pages only when required.

  • Page Replacement: Replace pages using algorithms like LRU, FIFO, Optimal.

Scenario: Running a 16 GB application on an 8 GB RAM system uses virtual memory with page swapping.


24. Explain Page Replacement Algorithms.

Answer:

Algorithm Description Pros Cons
FIFO Replace oldest page Simple High page fault rate
LRU Replace least recently used Good performance Needs tracking
Optimal Replace page that won’t be used for longest Minimum page fault Impossible in real OS
LFU Replace least frequently used Useful in some apps Old pages can stay too long

Scenario: Browser tab usage can be modeled using LRU to manage cache pages.


25. What is Thrashing in OS?

Answer:
Thrashing occurs when too many processes compete for memory, causing excessive page swapping and CPU idle time.

Detection: High page fault rate, low CPU utilization.
Solution: Reduce multiprogramming level, increase RAM, or use working set model.


26. Explain Kernel vs. User Space.

Answer:

Feature Kernel Space User Space
Privileges Full Limited
Access Hardware System calls only
Crash Risk OS crash Only app crash
Examples Device drivers, OS core Applications, Scripts

Scenario: When you open a file, user-space requests go via system calls, switching to kernel mode.


27. What are System Calls?

Answer:
System calls allow applications to request OS services.

Categories:

  • Process control: fork(), exit()

  • File operations: open(), read(), write()

  • Device operations: ioctl(), read(), write()

  • Communication: pipe(), msgget(), socket()

Scenario: Reading from a file triggers a read() system call.


28. Explain Inter-Process Communication (IPC).

Answer:
IPC allows processes to share data and synchronize.

Mechanisms:

  • Pipes (unidirectional, bidirectional with named pipes)

  • Message Queues

  • Shared Memory

  • Semaphores

  • Sockets

Scenario: Web server (process A) sends logs to logging process (process B) using shared memory.


29. What is a Semaphore and its Types?

Answer:
Semaphore is a synchronization primitive to avoid race conditions.

Types:

  • Binary semaphore (mutex): 0 or 1

  • Counting semaphore: Non-negative integer

Operations:

  • wait() or P() – Decrement semaphore

  • signal() or V() – Increment semaphore

Scenario: Controlling access to a printer by multiple processes using a binary semaphore.


30. Explain Deadlock Handling in OS.

Answer:

Deadlock Prevention: Ensure one of Coffman’s conditions doesn’t hold.
Deadlock Avoidance: Use Banker’s Algorithm for resource allocation.
Deadlock Detection & Recovery: Use Wait-for Graph and terminate/restart processes.

Scenario: Two processes holding Printer & Scanner indefinitely → deadlock detected and resolved by terminating one process.


31. What is the difference between Monolithic Kernel and Microkernel?

Feature Monolithic Kernel Microkernel
Size Large Small
Modules All OS services in kernel Only essential services
Performance Fast Slower due to message passing
Stability Less stable More stable
Example Linux, Unix Mach, Minix

32. Explain File System Management.

Answer:
File system provides:

  • Storage allocation (contiguous, linked, indexed)

  • File naming & access control

  • Directory structures (hierarchical/tree, flat)

Example: Linux uses ext4, Windows uses NTFS.


33. Explain Disk Scheduling Algorithms.

Answer:
Improves disk I/O performance.

Algorithm Description
FCFS First come first served
SSTF Shortest seek time first
SCAN Elevator algorithm
C-SCAN Circular scan for fairness
LOOK/C-LOOK Variation of SCAN with dynamic end detection

Scenario: Hard drive head moves optimally using SCAN to service read/write requests.


34. What is a Real-Time Operating System (RTOS)?

Answer:
RTOS ensures tasks are executed within strict timing constraints.

Types:

  • Hard real-time: Deadline must be met (e.g., pacemakers)

  • Soft real-time: Deadlines desirable but not strict (e.g., video streaming)

Features:

  • Deterministic scheduling

  • Minimal latency

  • Predictable interrupt handling


35. Explain Swapping.

Answer:
Swapping moves processes between RAM and disk to free memory.

Scenario: Linux swaps out idle processes to disk to free RAM for active processes.


36. What is the difference between Logical and Physical Address?

Feature Logical Address Physical Address
Definition Generated by CPU Actual RAM address
Viewpoint Program/Compiler Memory unit
Translation Through MMU Direct
Example Virtual addresses in process Actual memory frames

37. Explain Multithreading.

Answer:
Multiple threads within a single process share memory but execute independently.

Benefits:

  • Better CPU utilization

  • Responsiveness

  • Resource sharing

Scenario: Web server handles multiple client requests using threads.


38. What is a Race Condition?

Answer:
Occurs when multiple processes access shared resources concurrently and the final outcome depends on execution order.

Solution: Mutexes, semaphores, monitors.

Scenario: Two threads updating a bank account simultaneously → wrong balance.


39. What is Context Switching?

Answer:
Switching CPU from one process to another.

Steps:

  1. Save current process state (PC, registers)

  2. Load next process state from PCB

  3. Resume execution

Scenario: Multitasking OS switches between browser, IDE, and terminal.


40. What is Starvation in OS?

Answer:
Occurs when low-priority processes never get CPU time due to high-priority processes continuously running.

Solution: Aging – gradually increase priority of waiting processes.


41. Explain OS Security and Protection Mechanisms

Answer:
OS security ensures data and resource safety from malicious users or processes.

Key Mechanisms:

  1. Authentication: Verifies identity (passwords, biometrics).

  2. Authorization: Grants access based on user permissions.

  3. Encryption: Protects sensitive data (AES, RSA).

  4. Access Control:

    • Discretionary Access Control (DAC) – owner decides access

    • Mandatory Access Control (MAC) – OS enforces strict policies

  5. Audit Trails: Logs all user activities for detection and recovery.

Scenario: Linux chmod sets file permissions to prevent unauthorized access.


42. What is a Device Driver?

Answer:
A device driver is software that controls and communicates with hardware.

Types:

  • Character devices: Read/write data sequentially (keyboard, mouse)

  • Block devices: Read/write data in blocks (disk, SSD)

  • Network devices: Ethernet, Wi-Fi cards

Scenario: Printer driver converts OS print commands into signals the printer hardware understands.


43. Explain Kernel Data Structures

Answer:
The kernel uses data structures to manage processes, memory, files, and devices.

Key Structures:

  • Process Control Block (PCB): Stores process info (state, registers, priority).

  • File Control Block (FCB): Stores metadata of files.

  • Page Tables: Maps virtual pages to physical frames.

  • Ready Queue / Wait Queue: Maintains process scheduling.

Scenario: During context switch, PCB is used to save and load process state.


44. Explain Linux and Windows OS Internals

Answer:

Linux:

  • Monolithic kernel

  • Supports preemptive multitasking

  • Uses virtual memory, paging, and segmentation

  • File systems: ext3/ext4, XFS

  • System calls via syscall interface

Windows:

  • Hybrid kernel (monolithic + microkernel)

  • Supports threads, processes, and preemptive multitasking

  • NTFS file system

  • Device drivers managed via Kernel Mode Driver Framework (KMDF)

Scenario: fork() in Linux creates a new process, while Windows uses CreateProcess().


45. Explain Advanced Inter-Process Communication (IPC)

Answer:

Advanced Methods:

  1. Message Passing: Safe for distributed systems.

  2. Shared Memory: Fastest IPC; synchronization via semaphores.

  3. Sockets: Network-based IPC between processes on different machines.

  4. Remote Procedure Call (RPC): Allows a process to execute code on a remote machine.

Scenario: Microservices communicate using sockets and RPC over a network.


46. Explain Deadlock Detection Algorithms

Answer:
Detection is needed when deadlock is possible.

  • Wait-for Graph: Nodes = processes, edge P1→P2 means P1 waits for P2.

    • Cycle → Deadlock exists.

  • Banker’s Algorithm: Tracks resources, checks for safe state.

Scenario: If two database transactions hold locks on each other’s resources, OS detects the cycle in wait-for graph and resolves it.


47. Explain Paging vs Segmentation vs Virtual Memory

Feature Paging Segmentation Virtual Memory
Unit Fixed-size pages Variable-size segments Pages + Disk swap
Fragmentation Internal External Solves both via demand paging
Address Mapping Page Table Segment Table Page Table + Disk mapping
Use-case General memory mgmt Logical division Run programs > RAM

Scenario: Modern OS combines paging and segmentation for efficient memory management.


48. Explain Loadable Kernel Modules (LKM) in Linux

Answer:
Loadable Kernel Modules allow dynamic addition of functionality to the kernel without rebooting.

Benefits:

  • Extend kernel features (drivers, filesystems)

  • Reduce memory usage (load on-demand)

  • Easier debugging

Scenario: Adding a new USB device driver as a module without restarting Linux.


49. Explain POSIX Threads (Pthreads)

Answer:
POSIX Threads are standardized threads in Unix/Linux, allowing concurrent execution within a process.

Key Features:

  • Lightweight threads share process memory

  • Thread functions: pthread_create, pthread_join, pthread_mutex_lock

  • Supports synchronization primitives like mutexes and condition variables

Scenario: Multi-threaded server using pthreads for handling multiple clients.


50. Explain Real-Time Scheduling Algorithms

Answer:

Algorithm Type Description
Rate Monotonic (RM) Fixed Priority based on period; shorter period → higher priority
Earliest Deadline First (EDF) Dynamic Task with earliest deadline gets CPU
Least Laxity First (LLF) Dynamic Task with least slack time gets CPU

Scenario: Embedded systems in cars use RM or EDF to ensure safety-critical tasks meet deadlines.


51. Explain Device Management Techniques

Answer:
OS manages devices to coordinate access and optimize performance.

Techniques:

  • Polling: CPU repeatedly checks device status (inefficient).

  • Interrupt-driven: Device notifies CPU on completion.

  • DMA (Direct Memory Access): Device writes directly to memory, freeing CPU.

Scenario: Disk I/O uses DMA to transfer large data blocks efficiently.


52. Explain Thread Synchronization Techniques

Answer:

Mechanisms:

  • Mutexes – Mutual exclusion locks

  • Semaphores – Counting and binary for resource control

  • Monitors – High-level abstraction encapsulating condition variables and mutexes

  • Spinlocks – Busy-wait for short critical sections

Scenario: Bank system ensures consistent account balance updates using mutexes.


53. Explain Multi-Level Feedback Queue Scheduling

Answer:
Advanced CPU scheduling algorithm that adjusts process priority dynamically based on behavior.

Features:

  • Multiple queues with different priorities

  • Processes that use CPU extensively are lowered in priority

  • Short processes get fast turnaround

Scenario: OS ensures interactive apps like editors are responsive, while background tasks are deprioritized.


54. Explain Linux Virtual File System (VFS)

Answer:
VFS is an abstraction layer allowing Linux to support multiple file systems.

Features:

  • Provides uniform interface for system calls like open(), read(), write()

  • Supports ext4, NFS, FAT, etc.

  • Helps OS work with local and network files seamlessly

Scenario: VFS allows mounting both ext4 disk and NFS network share with the same API.


55. Explain Swapping vs Paging vs Segmentation

Answer:

Feature Swapping Paging Segmentation
Unit Process Fixed-size pages Logical segments
Purpose Move entire process Manage memory efficiently Logical program division
Overhead High Medium Low/Medium
Example Unix swapping Linux paging Intel x86 segmentation

βœ… Summary of Topics Covered

  • Process & Thread Management: PCB, scheduling, context switch, IPC

  • Memory Management: Paging, segmentation, virtual memory, thrashing

  • Deadlock & Synchronization: Deadlock handling, semaphores, mutexes, monitors

  • File & Device Management: File systems, disk scheduling, device drivers

  • Advanced OS Topics: Kernel modules, real-time scheduling, Linux/Windows internals, VFS

  • Security & Protection: Authentication, authorization, DAC, MAC