Sunday, November 6, 2011

One Interesting Fact in C Under Linux

When we use fork( ) to create a child process the child process does not contain the entire data and code of the parent process. Then does it mean that the child process contains the data and code below the fork( ) call. Even this is not so. In actuality the code never gets duplicated. Linux internally manages to intelligently share it. As against this, some data is shared, some is not. Till the time both the processes do not change the value of the variables they keep getting shared. However, if any of the processes (either child or parent) attempt to change the value of a variable it is no longer shared. Instead a new copy of the variable is made for the process that is attempting to change it. This not only ensures data integrity but also saves precious memory

No comments:

Post a Comment