Docsity

Operating System - Process Syncronization - Notes, Study notes of Operating Systems

Partial preview of the text

Download Operating System - Process Syncronization - Notes and more Study notes Operating Systems in PDF only on Docsity!

PROCESS SYNCHRONIZATION

Process Synchronization

  • (^) Background
  • (^) The Critical-Section Problem
  • (^) Peterson’s Solution
  • (^) Synchronization Hardware
  • (^) Semaphores
  • (^) Classic Problems of Synchronization
  • (^) Monitors
  • (^) Synchronization Examples
  • (^) Atomic Transactions

Types of Process

  • (^) Cooperating Process
  • (^) Competitive Process
  • (^) Producer Consumer Problem is a type of cooperative process.

Interprocess communication

  • (^) Processes frequently need to communicate with other processes.
  • (^) For example, in a shell pipeline, the output of the first process must be passed to second process, and so on down the line.
  • (^) Thus there is a need for communication between processes, preferably in a well-structured way not using interrupts.
  • (^) This we refer as InterProcess Communication or IPC.

Interprocess communication

  • (^) In some operating systems, processes that are working together may share some common storage that each one can read and write.
  • (^) Example
    • (^) Memory Block
    • (^) Shared file
    • (^) Shared Variable

Example of IPC

A print spooler.

  • (^) When a process wants to print a file, it enters the file name in a special spooler directory.
  • (^) Another process, the printer daemon, periodically checks to see if so are any files to be printed, and if so removes their names from the directory and do the Job. Spooler Process 1 Process 2 in out

Example of IPC

  • (^) At a certain instant, slots 0 to 3 are empty (the files have already been printed) and slots 4 to 6 are full (with the names of files to be printed).

Example of IPC

  • (^) More or less simultaneously, processes A and B decide they want to queue a file for printing.

Example of IPC

  • (^) Eventually, process A runs again, starting from the place it left off last time.
  • (^) It looks at next free slot, finds a 7 there, and writes its file name in slot 7, erasing the name that process B just put there.
  • (^) Then it computes next free slot + 1, which is 8, and sets in to 8.

RACE CONDITION

  • (^) The spooler directory is now internally consistent, so the printer daemon will not notice anything wrong, but process B will never receive any output.
  • (^) Situations like this, where two or more processes are reading or writing some shared data and the final result depends on who runs precisely when, are called race conditions.

Critical Sections

  • (^) How do we avoid race conditions?
  • (^) It is important to find some way to prohibit more than one process from reading and writing the shared data at the same time.
  • (^) what we need is mutual exclusion
  • (^) The difficulty above occurred because process B started using one of the shared variables before process A was finished with it.

Critical Sections

  • (^) That part of the program where the shared memory is accessed is called the critical region or critical section.
  • (^) If we could arrange matters such that no two processes were ever in their critical regions at the same time, we could avoid race conditions.

Critical Sections

  • (^) At time T 2 process B attempts to enter its critical region but fails because another process is already in its critical region and we allow only one at a time. Mutual exclusion using critical regions.

Critical Sections

  • (^) Consequently, B is temporarily suspended until time T 3 when A leaves its critical region, allowing B to enter
  • (^) immediately Mutual exclusion using critical regions.