×

Operating System Tutorial

Operating System Practice

Process Synchronization and Inter Process Communication (IPC)

In this tutorial, we will learn about process synchronization, different solutions or algorithms used in synchronizing the different processes, inter-process communication (IPC), and IPC methods. By Amit Shukla Last updated : May 07, 2023

What is Process Synchronization in OS?

Process synchronization is the task of synchronizing the execution of processes in such a manner that no two processes have access to the same shared data and resource. In a multi process system when multiple processes are running simultaneously, then they may attempt to gain the access of same shared data and resource at a time. This can lead in inconsistency of shared data. That is the changes made by one process may not be reflected when other process accessed the same shared data. In order to avoid these types of inconsistency of data the processes should be synchronized with each other.

One of the important concepts related to process synchronization is that of the critical selection problem. Each process contains a set of code called critical section through which a specific task, such as writing some data to file or changing the value of global variable, is performed. To ensure that only one single process should be entering in critical section at a specific instant of time, the process needs to be coordinated with other by sending requests for entering the critical section. When a process is in its critical section, then no other process is allowed to enter in critical section during the time period when one process is in a critical section.

Solutions or algorithms used in synchronizing the different processes

The following are the different solutions or algorithms used in synchronizing the different processes of any operating system:

1. Peterson's Solution

Peterson's solution is one of the famous solutions to critical section problems. This algorithm is created by a computer scientist Peterson. Peterson's solution is solution to the critical section problem involving two processes. Peterson's solution states that when a process is executing in its critical state, then the other process executes the rest of code and vice versa. This insures that only one process is in the critical section at a particular instant of time.

2. Locking Solution

Locking solution is another solution to critical problems in which a process acquires a lock before entering its critical section. When a process finishes its executing process in the critical section, then it releases the lock. Then the lock is available for any other process that wants to execute its critical section. The locking mechanism also ensures that only one process is in the critical section at a particular instant of time.

3. Semaphore Solution

Semaphore solutions are another algorithm or solution to the critical section problem. It is basically a synchronization tool in which the value of an integer variable called semaphore is retrieved and set using wait and signal operations. Based on the value of the semaphore variable, a process is allowed to enter its critical section.

What is Inter Process Communication (IPC)?

Inter process communication is the method of communication which is used to make communication between process through which processes interact with each other for gaining access of shared data and resources.

Inter Process Communication (IPC) Methods

There are mainly two methods of inter process communication:

  1. Shared Memory
  2. Message Passing

1. Shared Memory

In the shared memory, a part of memory is shared between the processes. A process can write the data that it wants to share with other process. Similarly, another process can read the data that have been written by the other process.

The following figure shows the shared memory method of inter process communication.

shared memory method of IPC

2. Message Passing

In the message passing method, a process sends a message to another process for communication. This method allows the sharing of data between processes in the form of messages.

The following figure shows the message passing method of inter process communication.

message passing method of IPC



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.