in Operating System edited by
2,955 views
1 vote
1 vote

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 edited by
by
3.0k views

1 comment

$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 https://youtu.be/FdmT4300-is

1
1

2 Answers

1 vote
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

4 Comments

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

1
1

Yes u r right  . plz u see this video https://youtu.be/CN9_YXGdQV8 30:00 . its the same question. 

1
1
count should be 4. I think framing question might be wrong
0
0
0 votes
0 votes

option 1 can never be the answer. I mean how???

First thing to note is s3 and s2 needs to be executed sequentially.But most of the answers given makes concurrent execution which is wrong.

Second thing is lets assume that s3 and s2 can be executed concurrently then after execution they directly will jump to L3 without executing the below code from line 3-5 is never possible.

So 2 option should be right.

Related questions

3 votes
3 votes
1 answer
3