Introduction

The isolation of a process brings drawbacks, as processes work better together and when sharing information. Given this, processes can be categorized in this context as:

  • Independent1
  • Cooperating2

There are a lot of benefits to enabling cooperation between processes, such as efficiency, speed, and modularity. In order for process cooperation to happen, they need a form of communication that shares data between processes through sending and receiving operations. This is where IPC comes in.

Inter-Process Communication helps processes run better by exchanging information and coordinating actions. There are two basic models of Inter-Process Communication:

Shared Memory

This model allows processes to share memory directly. When processes run, the OS allocates a separate memory space for each process, also known as Process Address Space3. Normally, these memory spaces are isolated, and if another process tries to intervene or write in the address space of another process, the OS does not allow it.

To enable this communication, the system creates shared memory between processes using system calls, and it is usually created in the address space of the process that called it. Any process needing to access this shared memory must also attach it to its own address space.

It is important to note that once shared memory is allocated, the OS does not check what it is used for and what is written there. When you use certain apps such as a browser, even when opening one tab only, there are multiple processes under that, which shows an example of how a modular system works.

Message Passing

Sharing memory is not the only method of communication between processes. Through message passing, processes can remain isolated while passing messages, and the need to share address space is eliminated.

Messages can be passed through different methods such as pipes, sockets, and RPC. If one process wants to communicate with another, it makes a call to the OS so that it creates a link to the process it needs to communicate with.

How this works is that the OS creates a “mailbox” in its own address space where processes can send and receive messages. However, processes cannot directly read or write to mailboxes in kernel address space, so the OS must provide system calls for send() and receive() operations at the very least. With message passing, processes do not even need to be on the same machine to communicate through more advanced network routing.

Processes use ports for communication, and a process can expose a dedicated receiving port, often referred to as a listening port.

Problems in IPC

IPC can face difficulty when multiple processes are sharing resources. Configuring and synchronizing this sharing is a rather complex and delicate process, resulting in race conditions and sometimes security risks.

Dining Philosophers Problem

The Dining Philosophers Problem4 goes as follows: there are five philosophers sitting around a table, and each of them needs two forks to eat. If each of them picks up one fork at the same time, no one gets to eat, resulting in freeze and stagnation.

Solution

  • The use of semaphores5.
  • Philosophers pick up forks one at a time.

Producer-Consumer Problem

The Producer-Consumer Problem6 goes as follows: producers generate data while consumers remove that data. The point of this dilemma is to avoid producers generating data when the buffer is full and to avoid consumers removing data from an empty buffer.

Solution

  • Using mutexes7 to ensure only one process is accessing the shared buffer at a time.
  • Using semaphores to track the availability of space in the shared buffer.

  1. Independent Process: Independent processes are those processes whose task is not dependent on any other processes. Source ↩︎

  2. Cooperating Process: Cooperating processes are those processes that depend on other processes. They work together to achieve a common task in an operating system. These processes interact with each other by sharing resources such as CPU, memory, and I/O devices to complete the task. Source ↩︎

  3. Virtual Address Space: The virtual address space for a process is the set of virtual memory addresses that it can use. The address space for each process is private and cannot be accessed by other processes unless it is shared. Source ↩︎

  4. Dining Philosophers Problem: The Dining Philosophers Problem is a classic synchronization problem introduced by Edsger Dijkstra in 1965. It illustrates the challenges of resource sharing in concurrent programming, such as deadlock, starvation, and mutual exclusion. Source ↩︎

  5. Semaphore: A semaphore is a synchronization tool used in operating systems to manage access to shared resources in a multi-process or multi-threaded environment. It is an integer variable that controls process execution using atomic operations like wait() and signal(). Semaphores help prevent race conditions and ensure proper coordination between processes. Source ↩︎

  6. Producer-Consumer Problem: The Producer-Consumer Problem is a classic example of a synchronization problem in operating systems. It demonstrates how processes or threads can safely share resources without conflicts. This problem belongs to the process synchronization domain, specifically dealing with coordination between multiple processes sharing a common buffer. Source ↩︎

  7. Mutex Object: A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned. Only one thread at a time can own a mutex object, which is useful in coordinating mutually exclusive access to a shared resource. For example, to prevent two threads from writing to shared memory at the same time, each thread waits for ownership of a mutex object before executing the code that accesses the memory. After writing to shared memory, the thread releases the mutex object. Source ↩︎

© Credits: The writing and images on this page are the original work of the page author unless a source is explicitly cited.