Operating System
106503Module 3: Inter-process Communication
Q1b. Under direct communication, each process that wants to communicate must explicitly name the recipient or sender of the communication. This mechanism is known as ______ (i) Naming (ii) Message Passing (iii) Mailboxes (iv) Chatting20242m
Module 3: Inter-process Communication
View this question on its own page →Under direct communication, each process that wants to communicate must explicitly name the recipient or sender of the communication. This mechanism is known as ______
(i) Naming
(ii) Message Passing
(iii) Mailboxes
(iv) ChattingWorked SolutionAnswer: (i) Naming (Direct Naming / Direct Communication)
In IPC, direct communication requires sender/receiver to explicitly name each other (
send(P,message),receive(Q,message)). This is called naming / direct addressing. Indirect uses mailboxes/ports. Message Passing is the overall category, Naming is the specific mechanism for direct.Q1e. Which of the following mechanisms is NOT typically used to achieve mutual exclusion? (i) Strict alternation (ii) Event counters (iii) Message passing (iv) Virtual memory20242m
Module 3: Inter-process Communication
View this question on its own page →Which of the following mechanisms is NOT typically used to achieve mutual exclusion?
(i) Strict alternation
(ii) Event counters
(iii) Message passing
(iv) Virtual memoryWorked SolutionAnswer: (iv) Virtual memory
Mutual exclusion solutions: busy-wait (Peterson, strict alternation), hardware (TSL, swap), semaphores, monitors, message passing, event counters. Virtual memory is memory management, not synchronization.
Q1e. The Dining Philosopher Algorithm is a classic example of which problem? (i) CPU scheduling (ii) Memory fragmentation (iii) Process synchronization and deadlock (iv) File allocation20252m
Module 3: Inter-process Communication
View this question on its own page →The Dining Philosopher Algorithm is a classic example of which problem?
(i) CPU scheduling
(ii) Memory fragmentation
(iii) Process synchronization and deadlock
(iv) File allocationWorked SolutionAnswer: (iii) Process synchronization and deadlock
Dining philosophers share forks (resources); illustrates synchronization, deadlock, starvation. Classic IPC problem solved by semaphores/monitors.
Q1f. To avoid race condition the maximum number of processes that may simultaneously be inside the critical section is: (i) No Limit (ii) Two (iii) Three (iv) One20232m
Module 3: Inter-process Communication
View this question on its own page →To avoid race condition the maximum number of processes that may simultaneously be inside the critical section is:
(i) No Limit
(ii) Two
(iii) Three
(iv) OneWorked SolutionAnswer: (iv) One
Critical section property: at most one process may execute inside CS at any time to ensure mutual exclusion and avoid race condition.
Q1h. What is the main problem that the "Critical Section" concept aims to solve in concurrent programming? (i) Memory overflow (ii) Infinite loop termination (iii) Race condition between processes (iv) Lack of CPU resources20242m
Module 3: Inter-process Communication
View this question on its own page →What is the main problem that the "Critical Section" concept aims to solve in concurrent programming?
(i) Memory overflow
(ii) Infinite loop termination
(iii) Race condition between processes
(iv) Lack of CPU resourcesWorked SolutionAnswer: (iii) Race condition between processes
Critical section is code segment accessing shared data. Mutual exclusion ensures only one process executes CS at a time to prevent race where outcome depends on timing.
Q1j. In Peterson's solution for two processes, which condition ensures mutual exclusion? (i) Both processes wait infinitely (ii) Only one process enters the critical section at a time (iii) Both processes enter the critical section together (iv) The process with a higher ID always wins20242m
Module 3: Inter-process Communication
View this question on its own page →In Peterson's solution for two processes, which condition ensures mutual exclusion?
(i) Both processes wait infinitely
(ii) Only one process enters the critical section at a time
(iii) Both processes enter the critical section together
(iv) The process with a higher ID always winsWorked SolutionAnswer: (ii) Only one process enters the critical section at a time
Peterson's flags+turn ensures mutual exclusion, progress, bounded waiting for 2 processes without hardware support.
Q4. What do you understand by race condition? Give few example of arising of race condition in concurrent processing.201914m
Module 3: Inter-process Communication
View this question on its own page →What do you understand by race condition?
Give few example of arising of race condition in concurrent processing.
Worked SolutionRace Condition
Occurs when multiple processes/threads access shared data concurrently and outcome depends on order of execution.
Example: shared counterx=5, P1:x=x+1, P2:x=x-1interleaved without sync can give wrong result. Other examples: lost update in database, inconsistent file write, printer spooler with two producers updating buffer indices.
Requires mutual exclusion, atomic operations.Q4a. What do you understand by critical section problem. Discuss the requirements that a solution to the critical section problem must satisfy.20227m
Module 3: Inter-process Communication
View this question on its own page →What do you understand by critical section problem. Discuss the requirements that a solution to the critical section problem must satisfy.
Worked SolutionCritical Section Problem
Code segment where shared resources accessed. Requirements: 1) Mutual Exclusion (only one in CS), 2) Progress (decision in finite time if no one in CS), 3) Bounded Waiting (limit on waiting). Solutions: software (Peterson), hardware (TSL, swap), semaphores, monitors.
Q5. (a) Define semaphore. Give a scheme for implementation of semaphore primitives. (b) What do you mean by critical section problem? What is the solution to the critical section problem?201914m
Module 3: Inter-process Communication
View this question on its own page →(a) Define semaphore. Give a scheme for implementation of semaphore primitives.
(b) What do you mean by critical section problem? What is the solution to the critical section problem?
Worked Solution(a) Semaphore & Primitives
Integer variable with atomic wait(S)/signal(V). Binary (0/1) vs counting. wait: while s≤0 wait, s-- ; signal: s++ and wake. Implementation via blocking queue, disable interrupts for atomicity.
(b) Critical Section
Segment accessing shared data. Requirements as before; solutions: mutex, semaphore (wait before CS, signal after), monitors.
Q6a. What is Semaphore? Explain with algorithm the Dining-Philosophers Solution using Monitors.20247m
Module 3: Inter-process Communication
View this question on its own page →What is Semaphore? Explain with algorithm the Dining-Philosophers Solution using Monitors.
Worked SolutionSemaphore
Integer sync variable. Dining Philosophers with Monitor: monitor with 5 condition vars, state[] = thinking/hungry/eating, test(i) checks neighbors not eating, pickup puts hungry then test, putdown sets thinking then tests neighbors. Monitor ensures mutex, prevents deadlock/starvation vs semaphore solution with deadlock risk.
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q7a. State producer-consumer problem. Give a solution to this problem using semaphore. Justify that your solution guarantees mutual exclusion.20236m
Module 3: Inter-process Communication
View this question on its own page →State producer-consumer problem. Give a solution to this problem using semaphore. Justify that your solution guarantees mutual exclusion.
Worked SolutionProducer-Consumer with Semaphore
Shared buffer size N, sem empty=N, full=0, mutex=1.
Producer: wait(empty), wait(mutex), produce to buffer, signal(mutex), signal(full)
Consumer: wait(full), wait(mutex), consume, signal(mutex), signal(empty)
Guarantees mutual exclusion via mutex, and counting sems prevent overflow/underflow, bounded waiting.Q7a. Explain the Producer-Consumer problem and discuss how semaphores can be used to solve it.20257m
Module 3: Inter-process Communication
View this question on its own page →Explain the Producer-Consumer problem and discuss how semaphores can be used to solve it.
Worked SolutionProducer-Consumer
As Q23: bounded buffer problem, solution with semaphores empty/full/mutex as above.
Q7b. Discuss critical section problem. Illustrate the classic software-based solution to this problem known as Peterson's solution.20238m
Module 3: Inter-process Communication
View this question on its own page →Discuss critical section problem. Illustrate the classic software-based solution to this problem known as Peterson's solution.
Worked SolutionCritical Section & Peterson
Critical section needs mutual exclusion, progress, bounded waiting. Peterson for 2 processes: shared flag[2], turn. Pi: flag[i]=true; turn=j; while(flag[j] && turn==j) wait; CS; flag[i]=false; remainder. Proves mutual exclusion.
Q8b. Write an algorithm for Readers-Writers Problem solution using Semaphores.20257m
Module 3: Inter-process Communication
View this question on its own page →Write an algorithm for Readers-Writers Problem solution using Semaphores.
Worked SolutionReaders-Writers with Semaphores
shared int readcount=0; sem mutex=1, wrt=1;
Reader: wait(mutex); readcount++; if(readcount==1) wait(wrt); signal(mutex); read; wait(mutex); readcount--; if(readcount==0) signal(wrt); signal(mutex);
Writer: wait(wrt); write; signal(wrt);
Readers preference variant, writer may starve; for writer preference add extra sem.Q9d. Write short notes on: Peterson's solution20227m
Module 3: Inter-process Communication
View this question on its own page →Write short notes on: Peterson's solution
Worked SolutionPeterson's Solution
Software mutual exclusion for 2 processes using flag[] and turn, guarantees mutex, progress, bounded waiting without hardware.