Operating-Systems-Notes

Inter Process Communication

Inter Process Communication(IPC) is an OS supported mechanism for interaction among processes (coordination and communication)

Message Passing

messagepassingipc.png

Advantages

Disadvantages

Forms of Message Passing IPC

1. Pipes

pipes.png

2. Message queues

msgq.png

3. Sockets

sockets.png

Shared Memory IPC

sharedmemoryipc.png

Advantages

Disdvantages

Which is better?

Overheads for

  1. Message Passing : must perform multiple copies
  2. Shared Memory : must establish all mappings among processes’ address space and shared memory pages

Thus, it depends.

Copy vs Map

Goal for both is to transfer data from one into target saddress space

Copy (Message Passing) Map (Shared Memory)
CPU cycles to copy data to/from port CPU cycles to map memory into address space
  CPU to copy data to channel
  If channel setup once, use many times (good payoff)
  Can perform well for 1 time use

Shared Memory and Synchronization

Use threads accessing shared state in a single addressing space, but for process

Synchronization method:

  1. mechanism supported by processing threading library (pthreads)
  2. OS supported IPC for sync

Either method must coordinate

IPC Synchronization

Message Queues Semaphores
Implement “mutual exclusion” via send/receive OS supported synchronization construct
  binary construct (either allow process or not)
  Like mutex, if value = 0, stop; if value = 1, decrement(lock) and proceed