11.03.2009

Processes do not share Global Variables



In the C code above, what are the values at line 13 and 18?

At line 13, the value is 30.
At line 18, the value is 10.

Why is this you ask? It's because the fork system call produces a new child process which does not share global variables with its parent process. Each process has its own code section and the data region. The run-time stack is copied for each process, thus they are not the same variable. Threads, on the other hand, do share global variables. Great. Now you tell me.

Can you think of a way to get around this limitation?

No comments:

Post a Comment