Fundamentals 65 min read

Master OS Interview Questions: From Basics to Advanced Concepts

This comprehensive guide covers over forty operating system interview questions, explaining core concepts such as OS fundamentals, process and thread management, memory handling, file systems, I/O mechanisms, scheduling algorithms, and deadlock prevention, providing detailed answers and diagrams to help candidates excel in technical interviews.

ITPUB
ITPUB
ITPUB
Master OS Interview Questions: From Basics to Advanced Concepts

Operating System Overview

An operating system is a crucial application that manages hardware and software resources, providing an interface between applications and the underlying hardware.

Main Functions of an OS

Process Management

: Schedules tasks, handling single‑core and multi‑core processors. Memory Management: Allocates and frees memory, using paging algorithms. Device Management: Manages device allocation and provides user interfaces. File Management: Organizes storage, ensuring efficient access and protection. User Interface: Offers system calls for applications to interact with hardware.

Software Access to Hardware

Software interacts with hardware via I/O operations, which can be parallel or serial. Three guiding principles for I/O control are fast data transfer without loss, low system overhead, and maximal hardware utilization. Direct Access: Busy‑wait method where the process directly controls I/O. Interrupt‑Driven: Uses interrupts to reduce CPU waiting. DMA: Direct Memory Access offloads transfer work from the CPU. Channel Control: Dedicated channel processors handle I/O independently.

Why OS Calls Are Called “Traps”

When a user program needs OS services, it triggers a system call, causing the CPU to switch from user mode (privilege level 3) to kernel mode (privilege level 0). The transition is visualized as the program “falling into” the kernel.

User Mode vs Kernel Mode

Kernel Mode

: Full access to memory and devices; can switch processes without preemption. User Mode: Restricted access; cannot directly manipulate hardware.

These modes exist to protect the system from dangerous operations such as clock setting or memory cleanup.

Mode Switching Process

User program calls the glibc library. glibc prepares the system‑call parameters.

It executes a software interrupt (SWI) which updates the CPSR register and jumps to address 0x08.

The CPU now runs kernel code.

The interrupt handler jumps to vector_swi().

The system‑call number is used to index the sys_call_table and invoke the appropriate kernel function.

After handling, the CPU restores user‑mode registers and resumes execution.

What Is a Kernel?

The kernel is the core program that controls all OS functions, loaded before the boot loader hands control to user space.

A boot loader loads the OS from the Master Boot Record (MBR) during power‑on self‑test (POST).

Real‑Time Systems

Real‑time OSes are classified as hard (strict deadlines) or soft (occasional deadline misses tolerated).

Linux Boot Process

After BIOS POST, the MBR loads a small program that loads the boot loader, which then loads the kernel. The kernel initializes hardware, creates the initial process (PID 0), then the init process (PID 1) which spawns a shell and other system services.

login:

Process and Thread

Advantages of Multiprocessor Systems

Multiple CPUs increase throughput and reliability while sharing resources such as memory and I/O.

Process vs Thread

A process is an executing program instance; a thread is a lightweight flow of execution within a process, sharing most resources.

Context Switch

A context switch transfers CPU control from one process to another, saving the current state and loading the next.

Benefits of Multithreading

Improved responsiveness.

Resource sharing.

Cost‑effective concurrency.

Deeper understanding of concurrent architectures.

Process Termination

Normal exit (e.g., exit on Unix, ExitProcess on Windows).

Error exit.

Fatal error.

Killed by another process (e.g., kill or TerminateProcess).

Inter‑Process Communication (IPC)

IPC mechanisms include message passing, FIFO queues, pipes, direct and indirect communication, message queues, and shared memory.

Process State Models

Three‑state model: Running, Ready, Blocked. Five‑state model adds New and Terminated states.

Scheduling Algorithms

First‑Come‑First‑Served (FCFS) : Simple but may cause long wait times.

Shortest Job First (SJF) : Non‑preemptive, selects the shortest remaining job.

Shortest Remaining Time (SRT) : Preemptive version of SJF.

Round‑Robin (RR) : Time‑slice sharing for interactive systems.

Priority Scheduling : Executes higher‑priority processes first.

Lottery Scheduling : Randomly selects a ticket‑holding process.

Fair Share Scheduling : Guarantees equal CPU share per user.

Memory Management

Demand Paging

Pages are loaded into memory only when accessed, causing a page‑fault if the page is not present.

Virtual Memory

Virtual memory extends physical RAM by swapping pages to disk, allowing programs to use more memory than physically available.

Implementation Techniques

Demand paging.

Demand segmentation.

Demand segment‑page.

Why Memory Is Segmented

Segmentation (originating from the 8086 CPU) enables relocation and access to the full address space by combining a segment base with an offset.

Address Types

Physical Address

: Actual hardware location. Logical/Effective Address: Segment base + offset. Linear Address: Result of segment translation in protected mode. Virtual Address: Linear address after paging.

Free‑Memory Management

Two common methods are bitmap allocation and free‑list allocation, each with its own allocation strategies (first‑fit, next‑fit, best‑fit, worst‑fit).

Page‑Replacement Algorithms

Optimal (theoretical benchmark).

NRU, FIFO, Second‑Chance, Clock.

LRU and approximations (NFU, Aging).

Working‑set based algorithms (WSClock).

File System

Improving File‑System Performance

Block Cache : Keep frequently accessed blocks in memory.

Read‑Ahead : Prefetch sequential blocks.

Minimize Disk Arm Movement : Allocate contiguous blocks on the same cylinder.

Inode Placement : Store inodes near the middle of the disk to reduce seek time.

Defragmentation : Re‑arrange files to reduce fragmentation (mostly unnecessary on SSDs).

Disk Arm Scheduling

Algorithms such as Shortest‑Seek‑Time‑First (SSTF), Elevator (SCAN), and others reduce seek time compared to simple FCFS.

RAID Levels

RAID 0: Striping without redundancy.

RAID 1: Mirroring.

RAID 2: Bit‑level ECC.

RAID 3: Bit‑interleaved parity.

RAID 4: Block‑interleaved parity.

RAID 5: Distributed parity.

RAID 6: Dual parity (P+Q).

I/O

System Clock

Clocks generate periodic interrupts (typically 50‑60 Hz) and can operate in one‑shot or square‑wave modes to provide timing services for the OS.

Device Controllers

Controllers are addressable hardware that manage character or block devices, handling command decoding, data transfer, address recognition, and error detection.

Interrupt Handling

Save registers not preserved by hardware.

Set up kernel context (TLB, MMU, page tables).

Switch to an interrupt stack.

Acknowledge the interrupt controller.

Store saved registers in the process table.

Execute the interrupt service routine.

Choose the next process to run (considering priorities).

Load the chosen process’s MMU context.

Restore its registers and PSW.

Resume execution.

Device Drivers

Drivers provide a software interface to hardware devices, abstracting device specifics from the OS.

Direct Memory Access (DMA)

DMA allows peripherals to transfer data directly to/from memory without CPU involvement, reducing bus contention and improving concurrency.

Deadlock

Zombie Processes

A zombie is a terminated process that remains in the process table until its parent reads its exit status.

Causes and Conditions

Mutual exclusion.

Hold‑and‑wait.

No preemption.

Circular wait.

Recovery Techniques

Resource preemption (difficult).

Rollback to a previous checkpoint.

Terminate one or more processes.

Deadlock Prevention

Eliminate mutual exclusion (e.g., use spooling for printers).

Disallow hold‑and‑wait by requiring all resources up front.

Allow preemption of resources.

Impose a total ordering on resource acquisition.

Deadlock Types

Two‑Phase Locking : Acquire all locks before any are released.

Communication Deadlock : Processes wait indefinitely for messages; avoided with timeouts.

Livelock : Processes keep changing state without progress.

Starvation : A process never obtains needed resources due to scheduling policies.

Virtual address mapping diagram
Virtual address mapping diagram
Process three‑state diagram
Process three‑state diagram
Process five‑state diagram
Process five‑state diagram
FCFS vs SSTF seek distances
FCFS vs SSTF seek distances
Shortest‑Seek‑Time‑First path
Shortest‑Seek‑Time‑First path
Elevator (SCAN) algorithm path
Elevator (SCAN) algorithm path
Resource ordering to prevent circular wait
Resource ordering to prevent circular wait
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Memory Managementconcurrencyprocess managementSchedulingOperating Systeminterview-questionsfile system
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.