Process synchronization in operating system

Hello friends if you are searching for process synchronization in operating system then you are at right place so let’s get started.

Process synchronization in operating system

So first we need to understand what is synchronization in computer science manner the synchronization means the operation or activity of two or more things at the same time. Hope you understand so now let’s understand what is process synchronization.

Why process synchronization is needed?

If we are running more than one process at a time then there is two mode to execute that process here are that two modes.

1.   serial mode

2.   parallel mode

So let’s understand both in deeply

1.Serial mode

If we gives two task at a time than if tasks are star line by line than it calls serial mode here if the process execute and terminate then only second process can start.

For example we can say ATM when we want to do transection in ATM then only one person at a time allowed in ATM room like that.

And serial mode is safe and secure the parallel because that both process does not affect each other process. But in parallel there are some chances to affect that process to each other not every time but some times.


2.parallel mode

If we gives two task to computer and it conduct and execute both the process at a time then it calls parallel mode. Now a days we want multitasking we want more features in computer we want to do more than one work at a time at that time parallel mode of process helps operating system to do that things.

When we are using parallel process there are two types of parallel process or process synchronization let’s see that types.

1.   Co-operative process

2.   Independent process


Types of process synchronization


1.Co-operative process

So here the first question arise is why we call this process as co-operative so the answer is because of this type of process is share their data to each other that’s why we called it Co-operative process.

Now here we think what type of data they can share so they can share Variable, memory, code, resource (CPU, Printer, Scanner etc..) Let’s understand with examples. 

Suppose there are two process P1 and P2 Here I am showing you example. First I will write the examples then I will explain you.


Here I declare one common variable

                                                int Shared=5


                                    P1                                      P2


Step 1 :                  int x = Shared;                   int y =Shared;                           

Step 2 :                  x++;                                 y--;

Step 3 :                  sleep(1);                           sleep(1);

Step 4 :                  Shared = x;                       Shared = y;

note : (If you are using mobile phone then switch into desktop mode it gives you batter experiance) 

So Now I am explaining what I want to say is…

So Here I declare one common variable which is same for both process suppose now computer start the execution of both process at a time let’s understand step wise in step 1 I assign the value for both local variable.

In next step P1 has increment of variable and P2 has decrement of variable now in step 3 here the main problem is come into the picture here I used one sleep function sleep function is used to stop process for one second.

So now both process are running at a time now suppose P1 ping to cpu first to sleep so at this point the value of x is 6 and value of y is 4 so now p2 is running 1 second behind P2.

In step 4 P2 is still I second late from P1 here in step 4 I need to print the value of x and y but now that 1 second gap problem is happening value of x print first and y prints after x.

I know this is only one second gap but this code is only four line suppose there is tones of line code then what happen.

So this is the Co-operative process I hope you understand.


2.Independent process

This process is as like process name this process is fully independent as we seen in co-operative process they are used to share variable memory and code etc. but this process is not allowing to share any type of data in execution and process.

In Independent process they are fully dependent on their own data that’s why we are prefer this type of process in are operating system there are so many benefits of independent process.    

So after reading this full article on process synchronization in operating system I hope you get the answer what you want and if you any question you can feel free to ask me in comment section and if you like the article do not forget to share the article to your friends.

And if you want daily update from are website you can do email subscription so you can get direct information to your mail box so you never miss new information thank you for reading this article.      

Related Posts :

Post a comment