Basic CS [3i Infotech Placement]: Sample Questions 116 - 116 of 243

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 116


Describe in Detail


What is shared memory? What is semaphore? How to use it?


  • Shared memory allows program processes to exchange data more quickly than by reading and writing using the regular OS services.
  • Refers to an extra piece of memory attached to some addresses spaces for their owners to use.
  • Given figure shows two processes and their address spaces.
Two Processes and Their Address Space
  • A feature supported by UNIX System V, including Linux, SunOS and Solaris.
  • A shared memory segment is identified by a unique integer, the shared memory ID.


  • Semaphore is a simply a variable.
  • It is a shared resource in a multi-processing environment.
  • Provides signalling mechanism between the processes
  • Allows the processes to exclusively use certain shared structures- guaranteeing no disturbance from other processes.
  • The region of program that is to be run by only one process is called “critical section” . Critical section modifies shared state.
  • Semaphore provides simple and powerful mechanism to mutual exclusion among concurrent processes.
  • Two Types of Semaphore

    • Binary semaphore
    • Counting semaphore
Two Types of Semaphore
  • Binary semaphore:
    • Takes the value of 0 & 1.
    • Two major operations, wait and signal are defined on the semaphore.
    • Critical section controlled by the wait operation and exit from a critical region is taken by signal operation.
    • Used only mutex locks.
  • Counting semaphores:
    • Can take a count value instead of binary value.

Developed by: