Operating System Assignment-2
1. Terms related to IPC:
- Race condition: Occurs when multiple processes access shared data simultaneously, and the final result
depends on the order of execution. Leads to unpredictable results.
- Critical section: A part of a program where shared resources are accessed. Only one process should
execute in the critical section at a time to prevent data inconsistency.
- Mutual exclusion: A principle ensuring that only one process accesses the critical section at a time.
- Semaphores: Synchronization tools used to control access to shared resources using integer variables and
two operations: wait() and signal().
- Bounded waiting: A condition that ensures there is a limit on the number of times other processes can enter
their critical section after a process has requested to enter its critical section.
- Mutex: A binary semaphore used to provide mutual exclusion; only one thread can hold the mutex at a time.
- Pipe: A unidirectional communication channel allowing one process to communicate with another by
sending data through the pipe.
- Message passing: A method of IPC where processes communicate by explicitly sending and receiving
messages without sharing variables.
2. Bounded Buffer (Producer-Consumer) using Semaphores:
- Uses three semaphores: 'empty' (initially buffer size), 'full' (initially 0), and 'mutex' (initially 1).
- Producer waits for empty slot and mutex, produces item, and signals full.
- Consumer waits for full slot and mutex, consumes item, and signals empty.
3. Readers-Writers Problem:
- A classic synchronization problem where many readers can read a resource simultaneously, but writers
need exclusive access.
Operating System Assignment-2
- Variants include: Reader-priority (no writer starvation) and Writer-priority (no reader starvation).
- Solved using semaphores and read/write counters.
4. Dining-Philosophers Problem:
- Five philosophers share five forks and a circular table. Each must pick up two forks (one at a time) to eat.
- Leads to potential deadlock if all pick one fork.
- Solutions include resource hierarchy, limiting philosophers at table, or using semaphores.
5. Deadlock and Conditions:
- A deadlock is a state where a set of processes are blocked waiting for each others resources.
- Four conditions for deadlock:
1) Mutual Exclusion
2) Hold and Wait
3) No Preemption
4) Circular Wait
6. Bankers Algorithm:
- Used to avoid deadlock by checking for safe states before allocating resources.
- Each process declares maximum resource needs. The system checks if resources can be safely allocated.
- Example:
Processes: P0, P1, P2
Max: [P0=7, P1=5, P2=3], Allocation: [P0=3, P1=2, P2=2]
Available: 3, Need: [P0=4, P1=3, P2=1]
Safe sequence: P2 P1 P0 (All can finish without deadlock)