0% found this document useful (0 votes)
20 views

Introduction of Process Synchronization _ GeeksforGeeks

Process synchronization is essential in computer systems to ensure that multiple processes can run concurrently without data inconsistency or interference. It involves techniques like semaphores and monitors to manage access to shared resources, preventing issues such as deadlocks and race conditions. The document also discusses types of processes, synchronization problems, and classical IPC problems like the Producer-Consumer and Dining Philosophers problems.

Uploaded by

Bhagya Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Introduction of Process Synchronization _ GeeksforGeeks

Process synchronization is essential in computer systems to ensure that multiple processes can run concurrently without data inconsistency or interference. It involves techniques like semaphores and monitors to manage access to shared resources, preventing issues such as deadlocks and race conditions. The document also discusses types of processes, synchronization problems, and classical IPC problems like the Producer-Consumer and Dining Philosophers problems.

Uploaded by

Bhagya Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

Search... 99+

Introduction of Process Synchronization


Last Updated : 10 Jan, 2025

Process Synchronization is used in a computer system to ensure that


multiple processes or threads can run concurrently without interfering
with each other.

The main objective of process synchronization is to ensure that multiple


processes access shared resources without interfering with each other
and to prevent the possibility of inconsistent data due to concurrent
access. To achieve this, various synchronization techniques such as
semaphores, monitors, and critical sections are used.

In a multi-process system, synchronization is necessary to ensure data


consistency and integrity, and to avoid the risk of deadlocks and other
synchronization problems. Process synchronization is an important
aspect of modern operating systems, and it plays a crucial role in
ensuring the correct and efficient functioning of multi-process systems.

On the basis of synchronization, processes are categorized as one of the


following two types:

Independent Process: The execution of one process does not affect


the execution of other processes.
Cooperative Process: A process that can affect or be affected by
other processes executing in the system.

Process synchronization problem arises in the case of Cooperative


Aptitude Engineering
processes alsoMathematics Discrete Mathematics
because resources are sharedOperating System DBMS
in Cooperative Computer N
processes.

Process Synchronization
Process Synchronization is the coordination of execution of multiple
processes in a multi-process system to ensure that they access shared
resources in a controlled and predictable manner. It aims to resolve the

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 1/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

problem of race conditions and other synchronization issues in a


concurrent system.

Lack of Synchronization in Inter Process Communication Environment


leads to following problems:

1. Inconsistency: When two or more processes access shared data at


the same time without proper synchronization. This can lead to
conflicting changes, where one process’s update is overwritten by
another, causing the data to become unreliable and incorrect.
2. Loss of Data: Loss of data occurs when multiple processes try to
write or modify the same shared resource without coordination. If
one process overwrites the data before another process finishes,
important information can be lost, leading to incomplete or corrupted
data.
3. Deadlock: Lack of Synchronization leads to Deadlock which means
that two or more processes get stuck, each waiting for the other to
release a resource. Because none of the processes can continue, the
system becomes unresponsive and none of the processes can
complete their tasks.

Types of Process Synchronization


The two primary type of process Synchronization in an Operating
System are:

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 2/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

1. Competitive: Two or more processes are said to be in Competitive


Synchronization if and only if they compete for the accessibility of a
shared resource.
Lack of Synchronization among Competing process may lead to
either Inconsistency or Data loss.
2. Cooperative: Two or more processes are said to be in Cooperative
Synchronization if and only if they get affected by each other i.e.
execution of one process affects the other process.
Lack of Synchronization among Cooperating process may lead to
Deadlock.

Example:
Let consider a Linux code:

>>ps/grep "chrome"/wc

ps command produces list of processes running in linux.


grep command find/count the lines form the output of the ps
command.
wc command counts how many words are in the output.

Therefore, three processes are created which are ps, grep and wc. grep
takes input from ps and wc takes input from grep.

From this example, we can understand the concept of cooperative


processes, where some processes produce and others consume, and
thus work together. This type of problem must be handled by the
operating system, as it is the manager.

Conditions That Require Process Synchronization


1. Critical Section: It is that part of the program where shared
resources are accessed. Only one process can execute the critical
section at a given point of time. If there are no shared resources, then
no need of synchronization mechanisms.
2. Race Condition: It is a situation wherein processes are trying to
access the critical section and the final result depends on the order in
which they finish their update. Process Synchronization mechanism

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 3/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

need to ensure that instructions are being executed in a required


order only.
3. Pre Emption: Preemption is when the operating system stops a
running process to give the CPU to another process. This allows the
system to make sure that important tasks get enough CPU time. This
is important as mainly issues arise when a process has not finished
its job on shared resource and got preempted. The other process
might end up reading an inconsistent value if process synchronization
is not done.

What is Race Condition?


A race condition is a situation that may occur inside a critical section.
This happens when the result of multiple process/thread execution in
the critical section differs according to the order in which the threads
execute. Race conditions in critical sections can be avoided if the critical
section is treated as an atomic instruction. Also, proper thread
synchronization using locks or atomic variables can prevent race
conditions.

Let us consider the following example.

There is a shared variable balance with value 100.


There are two processes deposit(10) and withdraw(10). The deposit
process does balance = balance + 10 and withdraw process does
balance = balance - 10.
Suppose these processes run in an interleaved manner. The deposit()
fetches the balance as 100, then gets preempted.
Now withdraw() get scheduled and makes balance 90.
Finally deposit is rescheduled and makes the value as 110. This
value is not correct as the balance after both operations should be
100 only

We can not notice that the different segments of two processes running
in different order would give different values of balance.

Critical Section Problem

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 4/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

A critical section is a code segment that can be accessed by only one


process at a time. The critical section contains shared variables that
need to be synchronized to maintain the consistency of data variables.
Sothe critical section problem means designing a way for cooperative
processes to access shared resources without creating data
inconsistencies.

In the above example, the operations that involve balance variable


should be put in critical sections of both deposit and withdraw.

In the entry section, the process requests for entry in the Critical
Section.

Any solution to the critical section problem must satisfy three


requirements:

Mutual Exclusion: If a process is executing in its critical section, then


no other process is allowed to execute in the critical section.
Progress: If no process is executing in the critical section and other
processes are waiting outside the critical section, then only those
processes that are not executing in their remainder section can
participate in deciding which will enter the critical section next, and
the selection cannot be postponed indefinitely.
Bounded Waiting: A bound must exist on the number of times that
other processes are allowed to enter their critical sections after a
process has made a request to enter its critical section and before
that request is granted.

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 5/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

Critical section Problem - Solutions

Classical IPC Problems


Various classical Inter-Process Communication (IPC) problems include:

Producer Consumer Problem


Readers-Writers Problem
Dining Philosophers Problem

Producer Consumer Problem


The Producer-Consumer Problem is a classic example of process
synchronization. It describes a situation where two types of processes
producers and consumers share a common, limited-size buffer or
storage.

Producer: A producer creates or generates data and puts it into the


shared buffer. It continues to produce data as long as there is space
in the buffer.
Consumer: A consumer takes data from the buffer and uses it. It
continues to consume data as long as there is data available in the
buffer.

The challenge arises because both the producer and the consumer need
to access the same buffer at the same time, and if they do not properly
synchronize their actions, issues can occur.

Key Problems in the Producer-Consumer Problem:

1. Buffer Overflow: If the producer tries to add data when the buffer is
full, there will be no space for new data, causing the producer to be
blocked.
2. Buffer Underflow: If the consumer tries to consume data when the
buffer is empty, it has nothing to consume, causing the consumer to
be blocked.

Producer-Consumer Problem - Solution (using Semaphores)

Readers-Writers Problem
https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 6/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

The Readers-Writers Problem is a classic synchronization problem


where multiple processes are involved in reading and writing data from
a shared resource. This problem typically involves two types of
processes:

Readers: These processes only read data from the shared resource
and do not modify it.
Writers: These processes modify or write data to the shared
resource.

The challenge in the Reader-Writer problem is to allow multiple readers


to access the shared data simultaneously without causing issues.
However, only one writer should be allowed to write at a time, and no
reader should be allowed to read while a writer is writing. This ensures
the integrity and consistency of the data.

Readers-Writers Problem - Solution (Readers Preference Solution)


Readers-Writers Problem - Solution (Writers Preference Solution)

Dining Philosophers Problem


The Dining Philosophers Problem is a well-known example that shows
the difficulties of sharing resources and preventing deadlock when
multiple processes are involved. The problem involves a set of
philosophers sitting around a dining table. Each philosopher thinks
deeply, but when they are hungry, they need to eat. However, to eat,
they must pick up two forks from the table, one from the left and one
from the right.

Problem Setup:

There are five philosophers sitting around a circular table.


Each philosopher has a plate of food in front of them and a fork to
their left and right.
A philosopher needs both forks to eat. If they pick up a fork, they
hold it until they finish eating.
After eating, they put down both forks and start thinking again.

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 7/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

The problem arises when multiple philosophers try to pick up forks at


the same time, which can lead to a situation where each philosopher
holds one fork but cannot get the second fork, leading to a deadlock.
Additionally, there’s a risk of starvation if some philosophers are
continually denied the opportunity to eat.

Dining Philosophers Problem - Solution (using Semaphores)

Advantages of Process Synchronization


Ensures data consistency and integrity
Avoids race conditions
Prevents inconsistent data due to concurrent access
Supports efficient and effective use of shared resources

Disadvantages of Process Synchronization


Adds overhead to the system
This can lead to performance degradation
Increases the complexity of the system
Can cause deadlock if not implemented properly.

Conclusion
Concurrent computing requires process synchronization to coordinate
numerous processes in a multi-process system to regulate and forecast
resource access. It addresses race situations and data inconsistency,
essential for data integrity. Semaphores and Peterson's solution are
used for synchronization. Synchronization is necessary for data
consistency but adds complexity and performance overheads, making
correct implementation and management vital for multi-process
systems.

Comment More info


Next Article
Advertise with us Race Condition Vulnerability

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 8/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

Similar Reads
Monitors in Process Synchronization
Monitors are a higher-level synchronization construct that simplifies
process synchronization by providing a high-level abstraction for data…

15+ min read

Process Synchronization
On the basis of synchronization, processes are categorized as one of the
following two types: Independent Process : Execution of one process do…

15+ min read

Bakery Algorithm in Process Synchronization


Prerequisite - Critical Section, Process Synchronization, Inter Process
Communication The Bakery algorithm is one of the simplest known…

15+ min read

Peterson's Algorithm in Process Synchronization


Peterson's Algorithm is a classic solution to the critical section problem in
process synchronization. It ensures mutual exclusion meaning only one…

15+ min read

Dekker's algorithm in Process Synchronization


Prerequisite - Process Synchronization, Inter Process Communication To
obtain such a mutual exclusion, bounded waiting, and progress there ha…

15+ min read

Semaphores in Process Synchronization


Semaphores are a tool used in operating systems to help manage how
different processes (or programs) share resources, like memory or data,…

15+ min read

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 9/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

Sleeping Barber problem in Process Synchronization


The Sleeping Barber problem is a classic problem in process
synchronization that is used to illustrate synchronization issues that can…

15+ min read

Centralized Clock Synchronization


Centralized Clock Synchronization is an internal clock synchronization
approach where clocks of system are synchronized with one of clock of…

12 min read

Introduction of Process Management


Process Management for a single tasking or batch processing system is
easy as only one process is active at a time. With multiple processes…

15+ min read

Critical Section in Synchronization


A critical section is a part of a program where shared resources like
memory or files are accessed by multiple processes or threads. To avoid…

15+ min read

Corporate & Communications Address:


A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305)

Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida, Gautam
Buddh Nagar, Uttar Pradesh, 201305

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 10/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

Advertise with us

Company Explore
About Us Job-A-Thon
Legal Offline Classroom Program
Privacy Policy DSA in JAVA/C++
Careers Master System Design
In Media Master CP
Contact Us Videos
Corporate Solution
Campus Training Program

Tutorials DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android

Data Science & ML Web Technologies


Data Science With Python HTML
Machine Learning CSS
ML Maths JavaScript
Data Visualisation TypeScript
Pandas ReactJS
NumPy NextJS
NLP NodeJs
Deep Learning Bootstrap
Tailwind CSS

Python Tutorial Computer Science


Python Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 11/12
06/06/2025, 08:37 Introduction of Process Synchronization | GeeksforGeeks

Kubernetes Interview Guide


Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Databases


Mathematics SQL
Physics MYSQL
Chemistry PostgreSQL
Biology PL/SQL
Social Science MongoDB
English Grammar

Preparation Corner More Tutorials


Company-Wise Recruitment Process Software Development
Aptitude Preparation Software Testing
Puzzles Product Management
Company-Wise Preparation Project Management
Linux
Excel
All Cheat Sheets

Courses Programming Languages


IBM Certification Courses C Programming with Data Structures
DSA and Placements C++ Programming Course
Web Development Java Programming Course
Data Science Python Full Course
Programming Languages
DevOps & Cloud

Clouds/Devops GATE 2026


DevOps Engineering GATE CS Rank Booster
AWS Solutions Architect Certification GATE DA Rank Booster
Salesforce Certified Administrator Course GATE CS & IT Course - 2026
GATE DA Course 2026
GATE Rank Predictor

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/introduction-of-process-synchronization/ 12/12

You might also like