Process Management Interview Questions Operating System (original) (raw)

Last Updated : 1 Sep, 2025

Process management is function of an operating system, responsible for creating, scheduling, and terminating processes. It ensures efficient CPU utilization through scheduling algorithms like FCFS, SJF, Priority, and Round Robin. Key concepts include process states, context switching, inter-process communication (IPC), and synchronization.

1. How does the OS handle priority inversion, and why can it be a critical problem in real-time systems?

Priority inversion occurs when a high-priority process is waiting for a resource held by a lower-priority process, but a medium-priority process preempts the lower-priority one, delaying the high-priority task indirectly. This is critical in real-time systems where deadlines are strict.
**Example:

**Solution techniques:

Without these, deadline misses or system stalls can occur in mission-critical tasks.

2. Explain how context switching works at the kernel level and why it’s considered an expensive operation.

Context switching is the act of storing the CPU state of a running process and loading the CPU state of another process. At the kernel level, it involves:

**Why expensive?

3. A system implements both preemptive and non-preemptive scheduling. Give a scenario where non-preemptive scheduling can outperform preemptive scheduling.

Non-preemptive scheduling can outperform in batch processing where context-switch overhead dominates and task durations are predictable.
**Example:

4. How does the OS avoid starvation in priority scheduling algorithms?

Starvation occurs when low-priority processes never get CPU time because high-priority processes keep arriving.
**Avoidance strategies:

  1. **Aging: Gradually increase a process’s priority the longer it waits, ensuring it eventually reaches the top priority.
  2. **Priority Queue Rotation: After a certain time quantum, temporarily drop the priority of a high-priority process to allow others execution.
  3. **Hybrid Scheduling: Combine priority with round-robin to give all processes some CPU share. These techniques balance responsiveness for urgent tasks with fairness for long-waiting jobs.

**5. Compare cooperative multitasking and preemptive multitasking in terms of process management complexity and stability.

**Cooperative multitasking: Processes voluntarily yield control; OS does not forcibly take CPU.

**Preemptive multitasking: OS scheduler interrupts processes to enforce time sharing.

In modern systems, preemptive multitasking is preferred despite the complexity, as it guarantees system responsiveness.

6. In multi-core processors, how does the OS decide whether to migrate a process to another core, and what are the trade-offs?

OS uses load balancing algorithms in the scheduler to decide migration:

**When? If one core is idle or underloaded while others are overloaded.

**Trade-offs:

Schedulers like Linux’s CFS use heuristics to minimize unnecessary migrations while balancing load.

**7. What’s the difference between a process state transition “Blocked → Ready” and “Running → Ready” in terms of scheduling?

**Blocked -> Ready:

**Running -> Ready:

This distinction matters because “Blocked -> Ready” transitions are event-driven, while “Running -> Ready” transitions are scheduler-driven.

8. Why is process creation more expensive in Unix-like systems than thread creation?

In Unix-like OS:

Thus, processes require more kernel work (memory mapping, resource allocation) compared to threads, making thread creation significantly faster.

9. How does the OS ensure atomicity when multiple processes request the same I/O device?

OS uses mutual exclusion mechanisms at the device driver level:

Atomicity ensures no partial I/O operations occur that could corrupt data or produce inconsistent results.

10. Explain the “thundering herd problem” in process synchronization and how OS mitigates it.

Occurs when multiple processes/threads are waiting for an event (e.g., socket readiness) and all are awakened when the event happens, but only one can proceed, causing excessive context switches and CPU waste.
**Mitigation:

11. Explain the concept of process starvation in OS. How can aging be used to prevent it?

Starvation occurs when a process waits indefinitely for CPU time because higher-priority processes keep getting scheduled. This is common in priority scheduling where lower-priority processes may never execute. Aging is a prevention technique where a process’s priority increases gradually the longer it waits.

**Example: A low-priority process might start with priority 1 but gain +1 every 5 seconds until it competes fairly with higher-priority processes. This ensures fairness without drastically affecting overall performance.

Aging is especially important in systems where certain jobs must not be delayed beyond a deadline.

12. Differentiate between preemptive and non-preemptive scheduling with real-time implications.

In hard real-time systems, preemption ensures deadlines are met, but it introduces context-switch overhead. Non-preemptive systems are simpler but unsuitable for urgent tasks.

13. How does the OS handle orphan and zombie processes?

The OS uses process reaping to remove zombies and process adoption mechanisms for orphans, ensuring no dangling processes persist indefinitely.

14. Explain how context switching affects CPU performance.

Context switching saves the state (registers, PC, stack pointer) of the current process and loads the state of the next scheduled process.

Optimizations include reducing unnecessary preemptions and grouping similar tasks to minimize cache misses. In real-time systems, context switch time is a critical factor for meeting deadlines.

15. How do inter-process communication (IPC) methods differ for message-passing vs shared-memory systems?

Hybrid systems combine both, shared memory for bulk data and message passing for control signals, to balance speed and safety.

16. What is the difference between process suspension and termination?

Suspension is reversible, termination is final. OS must manage suspended processes carefully to avoid deadlocks or priority inversions.

17. How does the OS implement process synchronization to avoid race conditions?

The OS uses mechanisms like mutex locks, semaphores, monitors, and spinlocks to control access to shared resources.
**Example: In the producer-consumer problem, semaphores manage buffer access, one semaphore tracks empty slots, another tracks filled slots. The OS ensures atomicity of these operations, preventing inconsistent states like multiple consumers accessing the same item simultaneously.

18. Describe the concept of process affinity and its types. Why is it important?

Process affinity (CPU pinning) binds a process to one or more specific CPUs to optimize cache performance.

Affinity reduces cache misses and improves performance for CPU-intensive tasks but can reduce load balancing efficiency.

19. How does the OS handle deadlock in process management?

The OS can:

  1. **Prevent: Remove at least one Coffman condition (e.g., by not allowing hold-and-wait).
  2. **Avoid: Use algorithms like Banker’s Algorithm to ensure safe state.
  3. **Detect & Recover: Periodically check for cycles in the resource allocation graph and preempt resources or kill processes to resolve

Choice depends on system type, real-time OS often prefer prevention or avoidance over detection.

20. Explain the difference between process and thread scheduling.

Multithreaded scheduling improves concurrency but may cause priority inversion if threads of different priorities share locks.