Gourav Jain gouravjain 11 Jan 2017 12:38 am

Please, explain the 4th question of the quiz??

Rahul rahul55523 11 Jan 2017 01:06 pm

how the address of parent and child process are same in question 4th

karmjit joshi karmjitjoshi 11 Jan 2017 04:21 pm

Consider the following code fragment:

if (fork() == 0)

{ a = a + 5; printf("%d,%d\n", a, &a); }

else { a = a –5; printf("%d, %d\n", a, &a); }



Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?

 u = x + 10 and v = y u = x + 10 and v != y u + 10 = x and v = y u + 10 = x and v != y

Sumit Verma sumitverma 11 Jan 2017 05:51 pm

Let's go line by line:

1.if (fork() == 0)

2. { a = a + 5; printf("%d,%d\n", a, &a); }

3. else { a = a –5; printf("%d, %d\n", a, &a); } 

Process P will execute line1. fork() will cause creation of a new child process say C1
Now Both P and C1 will start execution from the next instruction in line 1 which is the comparision of the returned value of fork() with zero.
For parent process P, this comparision is false as value returned by fork will be greater than 0(Process id of child process). So P will execute the else block.
For child process C1, Condition fork()==0 is true. So Cwill execute the if block.
Now u, v be the values printed by the parent process, and x, y be the values printed by the child process.
u= a-5, v=address of a (in parent process)
x= a+5, y=address of a (in child process)
Note one thing here: In virtual memory environment, all the processes start execution from the virtual address zero and hence both the process will have same logical address of the variable 'a' (physical address will be different).
Hence u + 10 = x and v = y is the correct option.

AMIT CHAUDHARY amit17 11 Jan 2017 07:05 pm
sir please increase the speed of uploading the lectures. thank you.
karmjit joshi karmjitjoshi 12 Jan 2017 12:59 pm

When the next video will be uploaded?

Rani Raja lovelyverma 12 Jan 2017 01:12 pm

yes plz tell sir?

Amit Jindal amitj 13 Jan 2017 12:40 am

Can anyone explain question 5 of quiz.

Chetna Wadhwa chetnawadhwa 14 Jan 2017 02:44 am

what about other days..after this..? haven't they been uploaded or are not accessible to me only..pl tell sum1

rahul sharma rahulkumarsh 14 Jan 2017 07:49 pm

Sir please upload next lectures and assignments . thanks a lot for the previous ones.