Quote:
|
then the only way you could have the fork'ed process modify the original process's variables would be to pass a pointer to the memory of the original process.
|
That won't work either because linux (or any modern operating system) uses virtual memory. No matter what address you choose in the child, 0x00000000 to 0xffffffff, it won't point to memory inside the parent. If you want a child and a parent which are able to affect eachothers' memory, you should use threads instead of processes. Other ways to handle communication between processos are pipes via pipe(), file i/o, messages via msgget() and friends, shared memory with shmget() and friends, communication over tcp or unix domain sockets, unix signals via kill(2), or, in very narrow cases, the exit code given to exit() in the child. (which the parent can see with wait(2) or waitpid(2)). There's More Than One Way To Do It(tm).
One thing you should watch out for with fork() is that you make sure the child process exits when it's supposed to. In your code it looks like the child will fall out of the if statement and begin executing the same code that the parent is supposed to. (You can fix this by having it exit() appropriately.)