The Gateway to Computer Science Excellence
+1 vote
225 views

Consider the code fragment: 

count = 3;
S1;
Fork L1;         L1: S3; S2;        goto L3;
S4;
Fork L2;         L2: S6;              goto L3;
S5;                 
L3: join count
S7 

Which one of the following represents correct precedence graph of the above code fragment?
the answer is given

but I’m getting

where am I wrong?

in Operating System by Active (5.1k points)
edited by | 225 views
0

$S_3$ and $S_2$ are concurrent processes since fork() system call was called at that level but you have shown dependency between them.. you can check here @11:00 something 

1 Answer

+1 vote

Answer should be this graph :Lightbox

count = 3; 
S1; 
Fork L1;         L1: S3;        goto L3;   // Create child process (S2,S3) If there is a Label with fork ,

                                                  means both are ( S2 and S3 )concurrent process .

                                                  S2 continue with this but S3 with Label L1

S2;                                    //   no fork :- their is no concurrency between S2 , S4 . so, S2 continue with S4

S4; 

Fork L2;         L2: S6;              goto L3 ;        // their is concurrency between S5, S6 . 

S5;         

         
L3: join count 


S7  

 

Join   count

        count=count-1

        if count!=0 , then

             Quit

by Junior (647 points)
0

shouldn't S3 and S4 be executing in parallel?

and after S3 is finished S2 will execute

as S2 comes after S3

Fork L1;         L1: S3; S2;        goto L3; 

0
No.

After S1 there is fork system call , with label L1 .and L1 is given S2,S3 . so , after S1 2 concurrent (parallel ) processes S2,S3 will be there . after that S4 comes .
0
L1 is S3; S2

not S2; S3

So S3 should be executed before S2?
+1

I've seen the vide @ankitgupta.1729 mentioned

As per your answer S2 and S3 is getting executed in parallel. But in question its mentioned L1: S3; S2

so a new process should be created that executes S3 then S2

0

Yes u r right  . plz u see this video  30:00 . its the same question. 

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,508 answers
195,518 comments
100,947 users