How OS is asked in technical interviews
Interviewers use OS to check whether you understand what happens beneath your code. Expect a definition followed by a scenario: two threads update a counter, what goes wrong and how do you fix it? Product companies go deeper into synchronization and memory, while IT services rounds usually stay with process states, scheduling and deadlocks.
OS basics: 8 questions
What is an operating system?
An operating system is the software layer between hardware and applications. It manages the CPU, memory, storage and devices, gives programs a clean interface through system calls, and keeps programs isolated and fair to each other. Linux, Windows, macOS and Android are examples.
What is the kernel?
The kernel is the core of the OS that runs in privileged mode. It handles process scheduling, memory management, device drivers, file systems and system calls. Everything else, such as the shell and desktop, runs as ordinary user programs on top of it.
What is the difference between a monolithic kernel and a microkernel?
A monolithic kernel runs most services, such as drivers and file systems, inside kernel space, which is fast but means a buggy driver can crash the system; Linux is monolithic with loadable modules. A microkernel keeps only the essentials in the kernel and runs other services as user processes, trading some speed for isolation.
What is a system call?
A system call is how a user program asks the kernel to do something privileged, such as reading a file, creating a process or sending data on a socket. The program triggers a controlled switch into kernel mode, the kernel does the work and returns. open, read, write and fork are common examples.
Why are there user mode and kernel mode?
To protect the system. In user mode a program cannot run privileged instructions or touch other programs' memory directly. Only the kernel, in kernel mode, can access hardware and all memory. A bug in my app can crash my app, but it should not crash the machine.
What is an interrupt?
An interrupt is a signal that makes the CPU pause its current work and run a handler. Hardware interrupts come from devices, such as a keyboard press or a disk finishing a read. Software interrupts or traps come from programs, such as system calls or a divide-by-zero error. Interrupts let the CPU avoid constant polling.
What happens when a computer boots?
Firmware, BIOS or UEFI, runs a power-on self test and finds a boot device. It loads a bootloader such as GRUB, which loads the kernel into memory. The kernel initialises hardware and memory, mounts the root file system and starts the first user process, such as systemd on most Linux systems, which starts the other services.
What are the main types of operating systems?
Batch systems run jobs without interaction. Time-sharing systems switch quickly between users so each feels in control. Real-time systems guarantee responses within deadlines, as in airbag or industrial controllers. Distributed systems make many machines work together, and embedded systems run inside devices such as routers and washing machines.
Processes and threads: 10 questions
What is the difference between a program and a process?
A program is a passive file of instructions on disk. A process is a program in execution, with its own memory, registers, open files and state. Opening the same browser twice creates two processes from one program.
What is a process control block?
The PCB is the kernel's record of a process. It holds the process id, state, program counter, CPU registers, scheduling priority, memory-management information such as page table pointers, open file list and accounting data. The kernel saves and restores it during context switches.
What are the states of a process?
New when it is being created, ready when it is waiting for the CPU, running when it is executing, waiting or blocked when it needs I/O or an event, and terminated when it has finished. A running process moves to ready when preempted and to waiting when it requests I/O.
What is a context switch, and why is it costly?
A context switch saves the state of the running process or thread into its PCB and loads the state of the next one. It is pure overhead: no useful work happens during it, and it often flushes caches and the TLB, so the next process starts slower. Too many switches waste CPU time.
What is the difference between a process and a thread?
A process has its own address space. Threads are units of execution inside a process that share its code, heap and open files, but each has its own stack and registers. Threads are cheaper to create and switch, and communicate through shared memory, but a bug in one thread can corrupt data for all.
What is the difference between user-level and kernel-level threads?
User-level threads are managed by a library without kernel knowledge, so switching is fast, but if one thread blocks on I/O the whole process may block. Kernel-level threads are scheduled by the kernel, so they can run on multiple cores and block independently. Most modern systems map each user thread to a kernel thread.
What does fork() return?
fork creates a copy of the calling process. It returns 0 in the child, the child's process id in the parent, and minus 1 in the parent if creation fails. The child often calls exec to load a new program, which is how a shell runs commands.
What are zombie and orphan processes?
A zombie is a child that has finished but whose parent has not yet read its exit status with wait, so its entry stays in the process table. An orphan is a child whose parent exited first; on Linux it is adopted by init or a subreaper, which later reaps it.
What are the ways processes communicate with each other?
Pipes and named pipes, message queues, shared memory, sockets, signals and memory-mapped files. Shared memory is the fastest because data is not copied, but it needs synchronization such as semaphores. Sockets work across machines as well as on one machine.
What are the benefits of multithreading?
Responsiveness, because a UI thread can stay active while a worker thread loads data. Resource sharing, since threads share memory. Lower cost than creating processes. And parallelism on multicore CPUs. The price is the need for careful synchronization.
CPU scheduling: 9 questions, with worked examples
What is the difference between preemptive and non-preemptive scheduling?
In non-preemptive scheduling, a process keeps the CPU until it finishes or blocks. In preemptive scheduling, the OS can take the CPU away, for example when a time slice ends or a higher-priority process arrives. Modern general-purpose systems are preemptive so that one process cannot hog the CPU.
What criteria are used to compare scheduling algorithms?
CPU utilisation and throughput should be high. Turnaround time, from arrival to completion, waiting time, spent in the ready queue, and response time, until the first response, should be low. Fairness and avoiding starvation also matter.
Four processes arrive at time 0 with burst times P1 6, P2 8, P3 7 and P4 3. Compare average waiting time under FCFS and SJF.
FCFS in order P1, P2, P3, P4 gives waiting times 0, 6, 14 and 21, an average of 41 divided by 4, which is 10.25. SJF runs P4, P1, P3, P2, giving P4 0, P1 3, P3 9 and P2 16, an average of 28 divided by 4, which is 7. SJF gives the minimum average waiting time.
With round robin and a time quantum of 4, processes P1 10, P2 4 and P3 5 arrive at time 0. Find the average waiting time.
Timeline: P1 runs 0 to 4, P2 4 to 8 and finishes, P3 8 to 12, P1 12 to 16, P3 16 to 17 and finishes, P1 17 to 19 and finishes. Waiting time is completion minus burst: P1 19 minus 10 is 9, P2 8 minus 4 is 4, P3 17 minus 5 is 12. The average is 25 divided by 3, about 8.33.
How does the time quantum affect round robin?
A very large quantum makes round robin behave like FCFS. A very small quantum gives good response time but spends too much time on context switches. A common rule of thumb is to pick a quantum longer than most short CPU bursts.
What is starvation, and how does aging fix it?
Starvation happens when a low-priority process never gets the CPU because higher-priority work keeps arriving. Aging gradually raises the priority of a process the longer it waits, so eventually it runs. SJF and priority scheduling are both prone to starvation.
What is the convoy effect?
In FCFS, if a long CPU-bound process is at the front of the queue, many short processes wait behind it, like cars behind a slow truck. Average waiting time rises and I/O devices sit idle. Preemptive algorithms such as round robin avoid it.
What is a multilevel feedback queue?
It uses several queues with different priorities and time slices. New processes start at high priority with a short slice. If a process uses its whole slice it moves down, so CPU-heavy jobs sink while interactive ones stay high. Aging moves long waiters back up.
What scheduling approach does Linux use?
For normal processes, Linux uses a fair scheduler that tracks how much CPU time each task has received and picks the one that is most behind, weighted by its nice value. For years this was the Completely Fair Scheduler, and recent kernels replaced it with an earliest-eligible-virtual-deadline design. Real-time tasks use separate FIFO and round-robin policies.
Synchronization: 10 questions
What is a race condition? Give an example.
A race condition is when the result depends on the timing of concurrent threads. If two threads each run count = count + 1 on a shared counter, both may read 5 and both write 6, losing one increment. The fix is to make the read, update and write a critical section protected by a lock or an atomic operation.
What is the critical section problem, and what must a solution guarantee?
A critical section is code that accesses shared data. A correct solution must guarantee mutual exclusion, so only one thread is inside at a time; progress, so the choice of who enters next is not postponed forever; and bounded waiting, so no thread waits indefinitely.
What is the difference between a mutex and a semaphore?
A mutex is a lock with ownership: the thread that locks it must unlock it, and it allows one thread at a time. A semaphore is a counter with wait and signal operations and no ownership. A counting semaphore can allow N threads at once, such as limiting a pool to 5 database connections.
What is the difference between binary and counting semaphores?
A binary semaphore takes only 0 or 1 and is used for mutual exclusion or simple signalling between threads. A counting semaphore can take any non-negative value and tracks how many units of a resource are available, such as free slots in a buffer.
Explain the producer-consumer problem and its solution.
A producer adds items to a bounded buffer and a consumer removes them. Use three semaphores: empty, starting at the buffer size; full, starting at 0; and a mutex. The producer waits on empty, locks, adds, unlocks and signals full; the consumer waits on full, locks, removes, unlocks and signals empty.
What is the readers-writers problem?
Many readers can read shared data at once, but a writer needs exclusive access. A simple solution lets readers in while no writer is active, using a reader count protected by a mutex. It can starve writers, so variants give writers priority or use fair queues.
What is the dining philosophers problem, and how can deadlock be avoided?
Five philosophers share five forks and each needs both neighbouring forks to eat. If all pick up their left fork at once, they deadlock. Fixes include making one philosopher pick up the right fork first, allowing at most four at the table, or picking up both forks only when both are free.
What is a spinlock, and when is it useful?
A spinlock makes a waiting thread loop, checking the lock repeatedly instead of sleeping. It wastes CPU while spinning but avoids the cost of sleeping and waking. It is useful on multicore systems when locks are held for very short times, as inside kernels.
What is a monitor?
A monitor is a high-level construct that bundles shared data with the procedures that access it and guarantees only one thread is active inside at a time. Condition variables let threads wait inside it for a condition. Java's synchronized methods with wait and notify follow this model.
What is priority inversion?
A high-priority task waits for a lock held by a low-priority task, while a medium-priority task preempts the low-priority one, so the high-priority task is effectively delayed by the medium one. Priority inheritance fixes it by temporarily raising the lock holder's priority to that of the highest waiter.
Deadlocks: 7 questions
What is a deadlock, and what are the four necessary conditions?
A deadlock is a set of processes each waiting for a resource held by another in the set, so none can proceed. All four conditions must hold: mutual exclusion, hold and wait, no preemption and circular wait. Breaking any one prevents deadlock.
How is deadlock prevention different from avoidance?
Prevention designs the system so that one of the four conditions can never hold, such as requiring all resources to be requested in a fixed global order to stop circular wait. Avoidance allows the conditions but checks each request at run time and grants it only if the system stays in a safe state, as the banker's algorithm does.
Explain the banker's algorithm.
Each process declares its maximum need. When a process requests resources, the OS pretends to grant them and checks whether there is still some order in which every process could get its remaining need and finish. If such a safe sequence exists, the request is granted; otherwise the process waits.
How is deadlock detected?
With single instances of each resource, the OS looks for a cycle in the wait-for graph. With multiple instances, it runs a detection algorithm similar to the banker's safety check on current allocations. Recovery means killing processes or preempting resources from a victim.
What is a resource allocation graph?
It is a directed graph with process nodes and resource nodes. A request edge goes from a process to a resource, and an assignment edge from a resource to a process. With one instance per resource, a cycle means deadlock; with several instances, a cycle means deadlock is possible but not certain.
What is the difference between deadlock and starvation?
In a deadlock, a group of processes wait on each other and none can ever proceed without outside action. In starvation, a process could run but keeps getting passed over, for example by a priority scheduler. Deadlock involves a cycle; starvation is a fairness problem.
What is a livelock?
In a livelock, processes keep changing state in response to each other but make no progress, like two people in a corridor who keep stepping aside the same way. Unlike deadlock, they are not blocked. Random back-off, as in network retry logic, usually breaks it.
Memory management and virtual memory: 13 questions
What is the difference between logical and physical addresses?
A logical or virtual address is what the program uses. A physical address is the real location in RAM. The memory management unit translates logical to physical addresses at run time, which lets each process believe it has its own private address space.
What are internal and external fragmentation?
Internal fragmentation is wasted space inside an allocated block, such as a process needing 13 KB getting four 4 KB pages and leaving 3 KB unused. External fragmentation is free memory split into small non-contiguous holes that together are large enough but individually are not. Paging removes external fragmentation.
What is paging?
Paging divides logical memory into fixed-size pages and physical memory into frames of the same size. A page table maps each page to a frame, so a process's memory need not be contiguous. A logical address is split into a page number and an offset within the page.
With 4,096-byte pages, logical address 13,000 is in a page mapped to frame 5. What is the physical address?
Page number is 13,000 divided by 4,096, which is 3 with a remainder: 3 times 4,096 is 12,288, so the offset is 712. Page 3 maps to frame 5, which starts at 5 times 4,096, or 20,480. The physical address is 20,480 plus 712, which is 21,192.
With a 32-bit logical address and 4 KB pages, how many entries does a single-level page table have?
4 KB is 2 to the power 12 bytes, so 12 bits are the offset and 20 bits are the page number. The table therefore has 2 to the power 20 entries, about one million. With 4-byte entries that is 4 MB per process, which is why multi-level page tables are used.
What is a TLB?
The translation lookaside buffer is a small, fast cache of recent page-to-frame translations in the MMU. On a TLB hit the address is translated without reading the page table from memory. Because programs reuse nearby pages, hit rates are high, which keeps paging fast.
What is segmentation, and how does it differ from paging?
Segmentation divides memory into variable-size logical units such as code, stack and heap, each with a base and limit. It matches how programmers think but suffers external fragmentation. Paging uses fixed-size blocks invisible to the programmer. Some systems combined the two.
What is virtual memory and demand paging?
Virtual memory lets a process use more address space than physical RAM by keeping only active pages in memory and the rest on disk. With demand paging, a page is loaded only when it is first accessed, which saves memory and speeds program start-up.
What happens on a page fault?
The MMU finds the page is not in memory and traps to the kernel. The kernel checks that the access is valid, finds a free frame or evicts a victim page, reads the needed page from disk, updates the page table and restarts the instruction that faulted.
For the reference string 7, 0, 1, 2, 0, 3, 0, 4 with 3 frames, count page faults under FIFO and LRU.
FIFO: 7, 0, 1 fault; 2 faults and evicts 7; 0 hits; 3 faults and evicts 0; 0 faults and evicts 1; 4 faults and evicts 2, a total of 7 faults. LRU: 7, 0, 1 fault; 2 evicts 7; 0 hits; 3 evicts 1; 0 hits; 4 evicts 2, a total of 6 faults.
What is Belady's anomaly?
It is the surprising case where giving FIFO more frames causes more page faults for some reference strings. Stack algorithms such as LRU and the optimal algorithm never show it, because the pages kept with n frames are always a subset of those kept with n plus 1.
What is thrashing, and how is it controlled?
Thrashing happens when processes do not have enough frames for their working sets, so the system spends most of its time swapping pages instead of running. CPU utilisation drops sharply. The fix is to reduce the number of active processes or allocate frames based on each process's working set or page-fault rate.
What is copy-on-write?
After fork, parent and child share the same physical pages, marked read-only. Only when one of them writes to a page does the kernel copy that page for the writer. This makes fork fast, especially when the child immediately calls exec.
File systems, disks and Linux: 9 questions
What is an inode?
In Unix-like file systems, an inode stores a file's metadata: size, owner, permissions, timestamps and pointers to its data blocks. It does not store the file name; directories map names to inode numbers. That is why one file can have several names through hard links.
What is the difference between a hard link and a soft link?
A hard link is another directory entry pointing to the same inode, so the file survives until every hard link is removed; hard links cannot normally cross file systems or point to directories. A soft or symbolic link is a small file containing a path, which breaks if the target is moved or deleted.
With the disk head at track 50 and requests 82, 170, 43, 140, 24, 16 and 190, what is the total head movement under SSTF?
SSTF always serves the nearest request: 50 to 43 is 7, then 24 is 19, then 16 is 8, then 82 is 66, then 140 is 58, then 170 is 30, then 190 is 20. The total is 208 tracks. SSTF reduces movement but can starve far requests, which SCAN avoids by sweeping like a lift.
What is DMA?
Direct memory access lets a device controller transfer a block of data between the device and memory without the CPU copying each byte. The CPU sets up the transfer and is interrupted only when it completes, which frees it for other work during large transfers.
What are RAID 0, RAID 1 and RAID 5?
RAID 0 stripes data across disks for speed with no redundancy, so one failure loses everything. RAID 1 mirrors data on two disks, surviving one failure at the cost of half the capacity. RAID 5 stripes data with distributed parity across at least three disks and survives one disk failure.
What is the difference between SIGTERM and SIGKILL?
SIGTERM politely asks a process to terminate; the process can catch it, clean up and exit, and it is what kill sends by default. SIGKILL cannot be caught or ignored and the kernel stops the process immediately, so it gets no chance to clean up. I try SIGTERM first.
What is swap space?
Swap is disk space used as an overflow for RAM. When memory is short, the kernel moves rarely used pages to swap to free frames. It prevents crashes under memory pressure, but heavy swapping makes the system slow because disk is far slower than RAM.
What happens, at the OS level, when you type ls in a terminal?
The shell reads the line and finds the ls program in the PATH. It calls fork to create a child, and the child calls exec to load ls. ls makes system calls to open and read the directory and to write the output to the terminal. The shell waits for the child and then shows the prompt again.
What is a daemon?
A daemon is a background process with no controlling terminal that provides a service, such as sshd for remote logins or cron for scheduled jobs. On most Linux distributions, daemons are started and supervised by systemd.
What the interviewer, and the AI panel, checks
- Precision: process vs thread in terms of what is shared, not a vague lighter-weight answer.
- Working through numericals aloud: scheduling tables, page faults and address translation.
- Connecting theory to code: a race condition in a counter, fork in a shell, swap on your laptop.
- Trade-offs: quantum size, spinlock vs sleeping lock, prevention vs avoidance.
Check your recall on the free operating systems basics test and the drawn placement CS fundamentals test, then answer these aloud in a mock technical round with the ExamPilot AI interviewer. For quick lab definitions, the operating system viva questions guide is the short version.
Two-week OS preparation plan
- 1
Days 1 to 3: processes and threads
Learn process states, the PCB, context switching, fork and exec. Run a tiny C or Python program that forks and prints process ids.
- 2
Days 4 to 6: scheduling
Solve ten FCFS, SJF, priority and round-robin problems by hand, drawing Gantt charts.
- 3
Days 7 to 9: synchronization and deadlocks
Write pseudocode for producer-consumer and readers-writers, then work two banker's algorithm examples.
- 4
Days 10 to 12: memory
Practise address translation, page table size and page-fault counting for FIFO, LRU and optimal.
- 5
Days 13 to 14: Linux and mock rounds
Revise inodes, links, signals and swap, then do two spoken mock rounds and tighten the answers that came out vague.
Frequently asked questions
- What are the most important OS topics for placement interviews?
- Process vs thread, process states and context switching, CPU scheduling algorithms with numericals, mutex vs semaphore and classic synchronization problems, deadlock conditions and the banker's algorithm, paging, page replacement and thrashing. These cover most fresher OS questions.
- Do interviewers ask OS numericals?
- Often, yes, especially scheduling waiting times, page-fault counts and address translation. They are quick to ask and show whether you understand the algorithm. Practise drawing Gantt charts and frame tables quickly and narrating each step aloud.
- How is an OS interview different from an OS viva?
- A viva checks syllabus definitions and lab programs. An interview checks reasoning: why a context switch is costly, how you would fix a race condition, what happens when a page fault occurs. Use the viva guide for definitions and this page for depth.
- Do I need to know Linux commands for fresher interviews?
- Basic familiarity helps, especially for backend, cloud and support roles: navigating files, permissions, processes, signals and logs. Interviewers like it when you connect OS concepts to commands you have actually used, such as ps for processes or kill for signals.
- Where can I practise OS questions for free?
- ExamPilot's operating systems basics test and placement CS fundamentals test are free, with explanations after each attempt. For spoken practice, run a technical mock interview with the AI interviewer, which asks follow-up questions like a real panel.
Practise out loud
Practise an OS technical round aloud
The AI interviewer asks operating system and CS fundamentals questions in a campus SDE round, follows up on your answers and flags vague explanations.
Big tech, Big 4 & IB campus · Big tech SDE / SDE intern (Amazon, Microsoft, Google, Flipkart, Swiggy, Zepto)
