Interprocess Communication (IPC)

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Why is it preferable for processes to communicate in a well-structured way without using interrupts?

  • Interrupts inherently cause deadlocks in process communication.
  • Interrupts ensure data integrity between processes.
  • Interrupts decrease overall system performance. (correct)
  • Interrupts are only for hardware signals, not interprocess communication.

In the context of interprocess communication (IPC), what is the significance of a 'spooler directory' in a printing system?

  • It stores temporary copies of documents being edited by users.
  • It is a dedicated space for storing printer drivers and configurations.
  • It serves as a buffer for completed print jobs before they are archived.
  • It holds file names waiting to be printed. (correct)

In a printing spooler system, what is the purpose of the 'out' and 'in' variables?

  • `out` indicates the printer's output queue status, while `in` manages the input buffer size.
  • `out` points to the next file to be printed, and `in` points to the next free slot in the directory. (correct)
  • `out` tracks the number of printed files, while `in` tracks the number of pending files.
  • `out` and `in` are flags that signal when a file has been completely printed and when a new file is ready for printing respectively.

Why is the scenario where multiple processes access and modify shared data, leading to unpredictable outcomes, referred to as a 'race condition'?

<p>Because the final result depends on which process executes when. (A)</p> Signup and view all the answers

What is the core objective of 'mutual exclusion' in the context of interprocess communication?

<p>To allow only one process to access shared resources at a time. (C)</p> Signup and view all the answers

What is the primary characteristic of a 'critical section' in a program?

<p>It's the part of the program where shared memory is accessed. (C)</p> Signup and view all the answers

Which of the following conditions is NOT a requirement for a valid solution to the critical section problem, according to Dijkstra's conditions?

<p>Processes must enter their critical sections in a FIFO (First-In-First-Out) manner. (C)</p> Signup and view all the answers

What is a potential drawback of using interrupt disabling as a method to ensure mutual exclusion?

<p>It's generally unattractive and unwise/risky to allow user processes to disable interrupts. (C)</p> Signup and view all the answers

What is the primary flaw of implementing mutual exclusion with a simple lock variable where processes test and set the lock before entering a critical section?

<p>Multiple processes can access the critical section simultaneously. (B)</p> Signup and view all the answers

What is the key issue with the 'strict alternation' approach to achieve mutual exclusion?

<p>It violates the condition that a process running outside its critical section should not block other processes. (B)</p> Signup and view all the answers

What is a significant drawback of Peterson's solution for achieving mutual exclusion?

<p>It wastes CPU time while processes are actively waiting. (A)</p> Signup and view all the answers

What does the test-and-set instruction do?

<p>Tests the lock variable and sets its value to true, returning the original value. (B)</p> Signup and view all the answers

How does the swap instruction aid in solving the critical section problem?

<p>It provides a way to atomically exchange a lock variable with a key variable. (B)</p> Signup and view all the answers

What are the two atomic operations associated with semaphores, as introduced by Dijkstra?

<p>DOWN and UP. (B)</p> Signup and view all the answers

What is the effect of the DOWN system call on a semaphore?

<p>It decrements the semaphore only if its value is greater than 0 otherwise, the requesting process is put to sleep. (A)</p> Signup and view all the answers

What is the purpose of the UP system call on a semaphore?

<p>It increments the value of the semaphore and wakes up all processes blocked on that semaphore. (A)</p> Signup and view all the answers

What is the primary purpose of semaphores in solving the critical section problem?

<p>To control access to shared resources, ensuring mutual exclusion. (C)</p> Signup and view all the answers

What is a typical usage of semaphores beyond critical section problems?

<p>Process synchronization. (C)</p> Signup and view all the answers

In the context of the bounded buffer (producer-consumer) problem, what is the role of the 'producer'?

<p>To generate items and fill the buffer slots. (B)</p> Signup and view all the answers

What constraints should be placed on the producer and consumer in the bounded buffer problem to prevent errors?

<p>The producer should not put items into filled slots, and the consumer should not try to consume items from empty slots. (B)</p> Signup and view all the answers

In the bounded buffer problem, what does the down(empty) operation achieve for the producer?

<p>It checks if there's space to write, and sleeps if the buffer is full. (B)</p> Signup and view all the answers

In the bounded buffer problem, what is the purpose of the up(full) operation performed by the producer?

<p>To indicate that a slot has been filled and increment the count of full buffer slots. (A)</p> Signup and view all the answers

In the readers and writers problem, under what condition is it acceptable for multiple processes to access a database concurrently?

<p>If all processes are performing read operations. (C)</p> Signup and view all the answers

In the readers-writers problem, why must a writer have exclusive access to the database?

<p>To ensure data consistency and prevent race conditions. (D)</p> Signup and view all the answers

In a basic implementation of the readers and writers problem, can 'down(db)' and 'up(db)' allow multiple readers?

<p>No, the semaphore prevents concurrent access and block other readers. (B)</p> Signup and view all the answers

What is the role of the 'rc' variable in a more sophisticated solution to the readers and writers problem, and why is it protected?

<p><code>rc</code> counts the number of processes reading the database; it's protected to avoid race conditions during updates. (D)</p> Signup and view all the answers

In the Dining Philosophers problem, what fundamental challenge does the scenario address?

<p>The problem of balancing resource allocation. (B)</p> Signup and view all the answers

In the Dining Philosophers problem, what might happen if each philosopher picks up their left chopstick simultaneously?

<p>A deadlock occurs, preventing any philosopher from eating. (C)</p> Signup and view all the answers

In a correct solution to the Dining Philosophers problem using an array state, what must be true for a philosopher to transition to the EATING state?

<p>Both neighbors must not be eating. (D)</p> Signup and view all the answers

In the Sleeping Barber problem, what happens when a customer arrives at the barber shop and all chairs are occupied?

<p>The customer leaves the shop (shop is full, do not wait). (D)</p> Signup and view all the answers

In the Sleeping Barber problem, what action does the barber take if there are no customers waiting?

<p>The barber sits down in the barber chair and falls asleep. (C)</p> Signup and view all the answers

In the Sleeping Barber problem, what is the role of the 'customers' semaphore?

<p>It counts the number of customers that are waiting. (C)</p> Signup and view all the answers

In the Sleeping Barber problem, what is the purpose of the 'barbers' semaphore?

<p>Signals the number of barbers that are ready to cut hair. (A)</p> Signup and view all the answers

A system uses a shared spooler directory with slots numbered 0 to 9 to manage print jobs. Currently, slots 0 to 4 are empty (printed), and slots 5 to 8 are full. The 'out' variable is 5, and the 'in' variable is 9. Process A reads 'in' and stores it as 9. Before process A can write its file name, a context switch occurs to Process B. Process B reads 'in', stores it as 9, puts its file in slot 9 and updates 'in' to 0. Then Process A resumes. What happens next?

<p>Process A will put its name to slot 9, overriding Process B file name. (D)</p> Signup and view all the answers

Consider the following strict alternation implementation:

int turn = 0;

Process P0:
while (TRUE) {
 while (turn != 0) { } // wait
 CS();
 turn = 1;
 Non-CS();
}

Process P1:
while (TRUE) {
 while (turn != 1) { } // wait
 CS();
 turn = 0;
 Non-CS();
}

What is the most significant problem if P0 is much slower?

<p>P1 is blocked even in P0’s non-critical section. (A)</p> Signup and view all the answers

A system has one writer and multiple reader processes accessing a shared database. The writer first executes think_up_data(), then calls down(db) and then write_database() and lastly calls up(db). The reader processes first executes down(db) calls read_database() and lastly calls up(db). What is the most significant problem of this system.

<p>This guarantees no concurrent reads which is not useful. (D)</p> Signup and view all the answers

Flashcards

Interprocess Communication (IPC)

Processes communicate under OS control, crucial for tasks like shell pipelines.

Spooler Directory

A directory where print jobs queue as files, managed by the printer daemon.

Printer Daemon

A process that manages the printer, checks for files to print, and sends to the printer.

Race Conditions

A situation where multiple processes access shared data, and the outcome depends on execution timing.

Signup and view all the flashcards

Mutual Exclusion

A mechanism to ensure only one process uses a shared resource at a time.

Signup and view all the flashcards

Critical Section (CS)

The part of a program that accesses shared memory or resources.

Signup and view all the flashcards

Disabling Interrupts

Disabling interrupts to prevent process switching during a critical section.

Signup and view all the flashcards

Lock Variable

A shared variable indicating whether a process is in a critical section.

Signup and view all the flashcards

Deadlock

Where multiple processes are blocked indefinitely, each waiting for a resource held by another.

Signup and view all the flashcards

Strict Alternation

Processes take turns entering a critical section, preventing simultaneous access.

Signup and view all the flashcards

Peterson's Solution

A solution for mutual exclusion using shared variables to indicate interest and turn.

Signup and view all the flashcards

Test-and-Set

Hardware instruction that atomically tests and sets a lock variable.

Signup and view all the flashcards

Semaphore

A variable type for process synchronization with 'down' and 'up' atomic functions.

Signup and view all the flashcards

DOWN System Call

If more than 0, decrement. If it is 0, the requesting process sleeps.

Signup and view all the flashcards

UP System Call

Increments the value of the semaphore and wakes up blocked processes.

Signup and view all the flashcards

Bounded Buffer (Producer-Consumer)

Processes exchanging data through a shared buffer.

Signup and view all the flashcards

Readers and Writers Problem

Allows multiple readers or one writer to access a database at a time.

Signup and view all the flashcards

Dining Philosophers Problem

Illustrates the challenges of resource allocation and deadlock avoidance

Signup and view all the flashcards

Sleeping Barber Problem

Illustrates concurrency issues, barber sleeps if no customers are waiting.

Signup and view all the flashcards

Study Notes

Interprocess Communication (IPC)

  • Processes often require communication with each other, as seen in a shell pipeline where output from one process is passed to the next.
  • Communication between processes managed by the OS is termed Interprocess Communication (IPC).
  • IPC should be well-structured, and avoid interrupts to maintain system performance.

IPC Example: Printing System

  • A process submits a file for printing by placing its name in a designated spooler directory.
  • A print daemon periodically scans this directory, and sends any listed files to the printer, and then removes names from directory.

Spooler Directory Setup

  • A spooler directory may have numbered slots (0, 1, 2, etc.) for storing file names.
  • Variables 'out' and 'in' can denote the next file to print and the next available directory slot, respectively.
  • These variables can be stored in a shared, two-word file accessible to all processes.

Race Conditions

  • Race conditions occur when multiple processes read or write shared data, and the outcome depends on the timing of their execution.
  • Mutual exclusion is needed, ensuring that only one process can access a shared variable/file at a time.

Critical Section

  • A critical section is a part of a program where shared memory is accessed.
  • Avoiding simultaneous execution of critical sections by multiple processes is essential to prevent race conditions.

Requirements for Critical Section Solutions (Dijkstra Conditions)

  • No two processes inside critical sections at same time; mutual exclusion is needed
  • There should be no assumptions about processor speeds or number of processors.
  • Processes outside critical sections should not block other processes.
  • No process should wait indefinitely to enter its critical section.

Simple Critical Section Structure

  • Processes Pi (i=0 and i=1) structure includes entry, critical section, exit code, and non-critical section components.

Methods for Preventing Critical Section

Disabling Interrupts

  • Simplest solution is to disable interrupts upon entering a critical section, and re-enable upon exiting.
  • Prevents processor switches, but also halts other processes from intervening shared memory.
  • This is generally not recommended to give user processes control of interrupts. A user could potentially halt the running of entire OS.

Lock Variables

  • Using a shared "lock" variable initialized to 0, processes check the lock before entering a critical section.
  • Setting it to 1 when entering and resetting to 0 when exiting.
  • Problems can still occur through the testing that creates fatal flaws.

Strict Alteration

  • In strict alternation, processes take turns entering critical sections based on a "turn" variable.
  • This is problematic because if a process is blocked by others outside of the Critical Section, condition 3 is voilated

Peterson's Solution

  • Peterson created a mutual exclusion lock algorithm to prevent 2 threads from concurrently accessing shared memory, and avoid race conditions
  • This well working process is problematic because it wastes CPU time while processes are actively waiting.

Test-and-Set Instruction

  • Test-and-set instruction returns true if lock is true, otherwise it first sets the value of lock to true and returns false.
  • Test-and-Set() can be used for the solution of the CS problem – still with active waiting.

Swap Instruction

  • The “swap” instruction interchanges the content of its parameters between int lock and int key.
  • This process still causes active waiting.

Semaphores

  • E.W. Dijkstra introduced semaphores, a new variable type with atomic DOWN and UP operations, for IPC solutions.
  • The DOWN system call checks if, and decrements a semaphore's value if it is above 0. Blocks the calling process puts it to sleep, otherwise.
  • The UP system call increases the semaphore's value, and wakes up all blocked processes.
  • Atomic nature of these operations which guarantees process isolation during semaphore modifications.
  • Semaphores can be used for CS problem as follows . semaphore mutex = 1;

Classical IPC Problems with Semaphores

  • Semaphores can be used to synchronize processes. For example, to ensure statement st2 of process p2 executes after st1 of p1.

Bounded Buffer (Producer-Consumer)

  • This problem involves producer and consumer processes who share a common buffer of n slots.
  • Producers fill the buffer, and consumers empty these slots.
  • Important to make sure consumers don't try to consume an empty slot, and producers don't try to write on full slots
  • This can be fixed with a mutex variable set to 1

Readers and Writers Problem

  • In a database system with multiple processes, multiple readers can access the database at the same time, although no one can when a writer is writing.
  • To fix this, the correct code should implement a read count and reading and updating code

Dining Philosophers Problem

  • N philosophers spend their lives thinking and eating in a room.
  • In their round table there is a plate of infinite rice and N chopsticks. Philosophers have one chopstick to the left, or right of them. They need 2 to eat.
  • The main point is to not cause deadlocks of philosophers

Sleeping Barber

  • A barber shop has one barber, one barber chair, and N chairs for waiting customers. If there is no customer at present, the barber sits down in the barber chair and falls asleep. When a customer arrives, he has to wake up the sleeping barber.
  • If additional customers arrive while the barber is cutting a customer's hair, they either sit down (if there is an empty chair) or leave the shop (if all chairs are full).
  • The problem is to program the barber and the customers without getting into race conditions or deadlocks.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Inter-Process Communication (IPC)
50 questions
Interprocess Communication (IPC)
29 questions

Interprocess Communication (IPC)

FelicitousSweetPea6902 avatar
FelicitousSweetPea6902
Use Quizgecko on...
Browser
Browser