In Linux, if the parent process has any data structures (e.g., trees, lists), are those data structures inherited by the child? I mean, does the child get access to the same data structure (any kind of pointer to that data structure)?
If you're talking about Linux/Unix processes after a fork()
, yes. They get their own copy of the data of the parent process, so whatever one of them does after the fork is not seen by the other (which is normally implemented by copy-on-write, so the memory pages won't get copied until written to, but that's a detail the user program doesn't see).
If you're talking about Windows starting a new process with CreateProcess()
, no, the new process does not inherit any data structure from the parent.
Both of these have much more to do with which OS you're using than with any specific programming language.
Assuming you are using something like fork()
to create the child processes, they'll inherit everything that's global for the actual parent process' context:
Global scope variables will be copied to the child process context from the state they actually are. Changes to these variables will not be reflected in the parent process.
If you want to communicate between parent and child processes, consider using pipes or shared memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With