Interview Q&A / Operating Systems

INTERVIEW Q&A · 42 QUESTIONS

Operating Systems interview questions

Processes, threads, scheduling, memory and deadlocks, in plain words.

  1. What is a race condition, and what is the critical section problem?

    A race condition happens when two or more threads access shared data at the same time and the result depends on the exact timing of their steps. The critical section is the part of code that touches that shared data, and the critical section problem is designing a way so only one thread runs it at a time, with progress and bounded waiting.

    BeginnerIn-depth3 min read
  2. What is context switching in an operating system?

    Context switching is when the OS pauses the process or thread running on a CPU, saves its state (registers, program counter, stack pointer) in its control block, and loads the saved state of another one so it can continue. It lets many programs share one CPU, but each switch is pure overhead.

    BeginnerIn-depth3 min read
  3. What is the difference between a mutex and a semaphore?

    A mutex is a lock that lets only one thread into a critical section at a time, and only the thread that locked it should unlock it. A semaphore is a counter that allows up to N threads to use a resource at once, and any thread can signal it, which also makes it useful for one thread to notify another.

    BeginnerIn-depth3 min read
  4. What is the difference between a process and a thread?

    A process is a running program with its own memory. A thread is a unit of work inside a process; threads of the same process share that memory, so they are lighter to create but need care to avoid clashing.

    BeginnerIn-depth2 min read
  5. A system has 4 KB pages. Translate logical address 20000 if page 4 is stored in frame 9.

    20000 = 4 x 4096 + 3616, so page number 4 and offset 3616. Frame 9 starts at 9 x 4096 = 36864, so the physical address is 36864 + 3616 = 40480.

    BeginnerQuick answer1 min read
  6. For burst times 24, 3 and 3 (all arriving at time 0), what is the average waiting time under non-preemptive SJF?

    SJF runs the shortest burst first: P2, P3, then P1. Waiting times are P2 0, P3 3, P1 6, so the average is (0 + 3 + 6) / 3 = 3 ms, which is the minimum possible.

    BeginnerQuick answer1 min read
  7. Three processes with burst times 24, 3 and 3 arrive together. What is the average waiting time under FCFS?

    Run in arrival order P1, P2, P3. Waiting times are 0, 24 and 27, so the average is (0 + 24 + 27) / 3 = 17 ms. Waiting time is the time a process spends in the ready queue before it gets the CPU.

    BeginnerQuick answer1 min read
  8. What are the states of a process in its life cycle?

    A process moves through new, ready, running, waiting (blocked) and terminated. The scheduler moves it between ready and running; I/O or events move it between running and waiting.

    BeginnerQuick answer1 min read
  9. What do threads of the same process share, and what does each thread keep private?

    Threads in one process share code, global data, the heap and open files. Each thread has its own stack, program counter, registers and thread ID.

    BeginnerQuick answer1 min read
  10. What does fork() return, and how does a program use that value?

    fork() creates a copy of the calling process. It returns 0 in the child, the child's PID in the parent, and -1 if creation failed. Programs branch on that value to run different code in each.

    BeginnerQuick answer1 min read
  11. What is a counting semaphore and when would you use one?

    A counting semaphore holds a non-negative integer that tracks how many units of a resource are free. wait() takes one unit (blocking at zero) and signal() returns one. It limits how many threads use a pool at once.

    BeginnerQuick answer1 min read
  12. What is a Process Control Block (PCB) and what does it store?

    A PCB is the kernel data structure holding everything the OS needs to manage one process: its ID, state, saved registers, program counter, memory information, open files and scheduling data.

    BeginnerQuick answer1 min read
  13. What is the difference between a logical address and a physical address?

    A logical (virtual) address is what the program generates; a physical address is the real location in RAM. The Memory Management Unit translates one into the other at run time.

    BeginnerQuick answer1 min read
  14. What is the difference between a zombie process and an orphan process?

    A zombie has finished running but still has an entry in the process table because its parent has not collected its exit status. An orphan is still running but its parent has died; init adopts it.

    BeginnerQuick answer1 min read
  15. What is the difference between paging and segmentation?

    Paging divides memory into fixed-size pages invisible to the programmer; segmentation divides it into variable-size logical units like code, stack and heap. Paging causes internal fragmentation, segmentation causes external.

    BeginnerQuick answer1 min read
  16. What is the difference between turnaround time, waiting time and response time?

    Turnaround time is completion minus arrival. Waiting time is turnaround minus burst, the total time spent in the ready queue. Response time is the time from arrival to the first time the process gets the CPU.

    BeginnerQuick answer1 min read