in Operating System edited by
1,561 views
3 votes
3 votes

 

in Operating System edited by
by
1.6k views

4 Comments

@Shaik Masthan

ans given D) 

0
0

@prashant jha 1

main()
{

fork() && fork() || fork().;

print("Gate");

}

Hey can you tell me about above statement....how they actually execute this line.....

After calling the start execution from next line...

Help please...

0
0

1 Answer

6 votes
6 votes
Best answer

Statement I - fork() creates a new process, and all local and global variables are copied to the new address space. Hence, the child process and parent process DO NOT share any variables, including global. So, this statement is false.*

Statement II - fork() creates a child process, with completely new address space, and hence they DO NOT share address spaces. The virtual addresses may look the same, however their physical addresses in the memory are different. So, this statement is false.

Statement III - Child process can terminate, on it's own. So, this statement is false.

Statement IV - Since, the parent can terminate on it's own without notifying child processes, thereby orphaning the child process, which are also known as zombie processes, this statement is false.

Statement V - fork() returns pid of child in the parent process, however in child process the pid is 0. (and -1 if it failed to create a child process) So, this statement is half correct, which makes it false.

 

[*] - Unix implements copy-on-write in the implementation of fork(), which is done for optimization. Copy-on-write means, the variables will be shared until they are modified. When they are being modified, the values will be copied to every address space.

 

selected by

1 comment

edited by

@toxicdesire @Shaik Masthan $Sir,$

Copy-on-write means, the variables will be shared until they are modified.  When they are being modified, the values will be copied to other address space.

if there is no modification(assumed) then can we say that they share common address space ? 

Statement II - fork() creates a child process, with completely new address space, and hence they DO NOT share address spaces. The virtual addresses may look the same, however their physical addresses in the memory are different. So, this statement is false.

By this statement it is indicating that in the beginning itself they separate there address space.

Is this true ?

https://stackoverflow.com/questions/4594329/difference-between-the-address-space-of-parent-process-and-its-child-process-in

https://stackoverflow.com/questions/6196552/sharing-address-space-versus-duplicating-the-page-table-entries/6200398#6200398

0
0

Related questions