Process Synchronization - Question Bank with Answers
1. Multiprogramming
Q: What is a multiprogramming OS?
A: Definition: An OS that allows multiple programs to run concurrently by managing CPU time among them.
Key Points:
- Uses CPU efficiently.
- Runs another process when one waits for I/O.
- Reduces CPU idle time.
Q: What are the benefits of multiprogramming?
A: - Increases CPU utilization.
- Improves system throughput.
- Reduces wait time for short jobs.
Q: Differentiate multitasking and multiuser OS.
A: Multitasking: Runs multiple tasks for one user.
Multiuser: Supports multiple users accessing the same CPU from terminals.
Q: Name the components of a multiprogramming OS.
A: - File System
- I/O Control System
- Command Processor
- Transient Area
Q: Give examples of multiprogramming OS.
A: - Windows
- UNIX
- MP/M
- XENIX
- DESQview
2. Process Synchronization
Q: What is process synchronization?
A: Definition: Ensuring multiple processes access shared resources safely.
Process Synchronization - Question Bank with Answers
Key Points:
- Prevents race conditions.
- Avoids inconsistent data.
- Ensures system stability.
Q: Why is synchronization required in multiprocessing?
A: - Prevents data corruption.
- Avoids deadlocks.
- Ensures fairness among processes.
Q: What are race conditions?
A: When multiple processes access and modify shared data concurrently, leading to unexpected outcomes.
Q: Explain inconsistency and deadlock.
A: - Inconsistency: Data mismatch due to unsynchronized access.
- Deadlock: Processes wait indefinitely for each other.
Q: Differentiate cooperative and independent processes.
A: Cooperative: Share resources and affect each other.
Independent: Execute without affecting other processes.
3. Critical Section Problem
Q: Define critical section.
A: A part of the code where shared resources are accessed. Only one process should execute it at a time.
Q: What are the three conditions of critical section solution?
A: - Mutual Exclusion
- Progress
- Bounded Waiting
Q: Explain mutual exclusion with example.
A: If Process P1 is in the critical section, P2 should wait. This prevents simultaneous access.
Q: What is bounded waiting?
A: A process should not wait forever to enter its critical section. There must be a limit.
Process Synchronization - Question Bank with Answers
Q: Why must solutions be hardware-independent?
A: To ensure portability and consistency across 32-bit and 64-bit systems.
4. Synchronization Techniques (Lock/Test-and-Set/Strict Alternation)
Q: How does a lock variable work?
A: It uses a binary value (0 or 1) to control access. 0 means free, 1 means occupied.
Q: Explain test-and-set instruction.
A: A hardware-supported atomic instruction. It checks and sets lock simultaneously to avoid race conditions.
Q: What is strict alternation?
A: Uses a 'turn' variable to alternate access between two processes. Ensures one at a time access.
Q: Drawback of using lock variable?
A: It may not provide bounded waiting. One process may repeatedly enter CS.
Q: Which technique ensures atomicity?
A: Test-and-Set ensures atomic execution using hardware-level support.
5. Classical IPC Problems
Q: Explain producer-consumer problem.
A: Producer adds items to buffer, consumer removes. Need synchronization to avoid overflow/underflow.
Q: What are key issues in producer-consumer problem?
A: - Buffer overflow
- Buffer underflow
- Inconsistent access without mutex
Q: What is reader-writer problem?
A: Multiple readers can read simultaneously, but writers need exclusive access.
Q: When does dining philosopher problem occur?
A: When all philosophers pick one chopstick and wait forever (deadlock).
Q: Why is dining philosopher a classic problem?
A: It shows real-world synchronization and deadlock challenges.
Process Synchronization - Question Bank with Answers
6. Semaphores
Q: What is a semaphore?
A: A variable used to control access to resources using wait() and signal() operations.
Q: Differentiate binary and counting semaphores.
A: - Binary: Only 0 or 1 (like lock).
- Counting: Multiple values, for multiple resource instances.
Q: How does wait() and signal() work?
A: - wait(): Decreases semaphore.
- signal(): Increases semaphore.
Q: How are semaphores used in producer-consumer?
A: Track available and full slots using two semaphores: empty and full, and a mutex for access.
Q: Advantages of semaphores?
A: - Prevents race conditions
- Ensures mutual exclusion
- Flexible for multiple problems