IPC

19 May 2022 . os .

Inter Process Communication

Pipe

  • Within one process or between child and parent.
  • One process write into the pipe and the other read from the pipe.
  • Temporary connection.

Named Pipe (FIFO)

  • A special kind of file on local storage
  • Allow two or more processes to communicate by reading or writing from the file.

Shared Memory

  • Available for multiple processes to access.
  • Need to be protected with synchronization when multiple processes communicate at same time.

Message Queue

  • Once a message is received by one process, it would be no longer available for any other processes.
  • Process A wants to send different data packets to Process B, C and D.

Semaphore

To protect critical region shared by multiple processes.

  • Binary Semaphore

    Only two states: 0/1, locked/unlocked, unavailable/available.

  • Counting Semaphore

    Assume there are 3 services to be fetched and we use semaphore to control visibility of the loading icon. At first, semaphore is 0 and loading icon will appear. Every time we fetch data successfully, let semaphore plus 1. When semaphore reach 3, the loading icon will disappear.

Signal