I have a global variable, X. I then fork and modify X from the child. I want those changes to show up in the parent, but I don't want the parent to have to wait on the child.
How can I do this?
I have a global variable, X. I then fork and modify X from the child. I want those changes to show up in the parent, but I don't want the parent to have to wait on the child.
How can I do this?
You cannot.
After forking, those are two separate processes. You will have to make use of some IPC.
You need to put the variable in shared memory. There are many ways to create shared memory. I'd probably just use
mmap
, but you could also check outshmget
orshm_open
.When you fork a new process that is a separate copy of the address space. It can only see the changes made before the fork.
If you want shared memory for communication between the processes, you have to create that explicitly.