Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Global Variables Not Updated in Child Process

by philipbailey (Chaplain)
on Nov 16, 2012 at 08:20 UTC ( #1004147=note: print w/replies, xml ) Need Help??


in reply to Global Variables Not Updated in Child Process

When you fork a process, then parent and child are initially more or less exact copies, including the values of variables, except for the return code of fork(). But the key word there is copies. Those two processes are now independent and variables, "global" or not, are not connected in any way.

That's fortunate, as for Unix-like operating systems, and probably others, all processes are ultimately children (or children of children etc.) of one startup process. If data were always shared between parent and child, all processes would have some common state.

As to how you can solve your problem, the best approach depends on the details of what you are doing. You could share data, for example, through disc files, or by various IPC mechanisms, e.g. sockets, pipes. See perlipc.

  • Comment on Re: Global Variables Not Updated in Child Process

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004147]
help
Chatterbox?
[marto]: your account is 7 days old, how old are these 'old tgimers'?
[choroba]: usemodpoerl Do you have a question? Do you want to help someone? Or do you just want to troll?
[usemodperl]: perlmonks used to be a safe space for perl coders, now it's like having an annoying girlfriend...
[marto]: I had a feeling I'd regret looking up the definition of 'soyboy'
[Veltro]: usemodperl Maybe it is the way you talk? 'Soy boys', 'old ladies' and what is even a tgimer...
usemodperl is venting, duh?
[usemodperl]: that was a typos, dumbass
[marto]: usemodperl I guess that depends on what you mean by a safe space, since many people seem to have the impression a safe space allows them to do/say whatever they feel like, without question or critque
[marto]: 'typos'->'typo'
[usemodperl]: it's like you guys are retarded or something, no sense of humor? autism?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-06-24 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (126 votes). Check out past polls.

    Notices?