Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Global Variables Not Updated in Child Process

by anshumangoyal (Scribe)
on Nov 19, 2012 at 11:56 UTC ( #1004520=note: print w/replies, xml ) Need Help??


in reply to Re: Global Variables Not Updated in Child Process
in thread Global Variables Not Updated in Child Process

So, is there anything I can use instead of forking? I want to run some processes in parallel and capture the results from them. My Prime focus is not forking but process some thing in a child process and get the values updated in parent.
  • Comment on Re^2: Global Variables Not Updated in Child Process

Replies are listed 'Best First'.
Re^3: Global Variables Not Updated in Child Process
by afoken (Monsignor) on Nov 21, 2012 at 18:13 UTC
    My Prime focus is not forking but process some thing in a child process and get the values updated in parent.

    So you want your son to learn French and your daugther to learn German, and you expect that you automatically speak both French and German as soon as both have finished learning. Does that work in real life? Nope. And it also won't work with fork()ed processes.

    Please read fork-exec, fork, and perhaps also exec.

    Generally, processes can't update other processes data. You need some kind of inter-process communication, or shared memory. Shared memory won't work well with Perl, because perl tends to move data around when its size changes. See perlipc for details on both ways.

    Another option, with its own set of traps, is using threads. Threads give you lightweight "processes" inside a single process, and threads can actually share variables. See perlthrtut for details. Of course, this works only if all external programs you are using now are merged into a single big program (possibly by moving each program into a single module).

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Dear afoken, the natural analogy is the parent process getting pregnant because the child process had sax

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004520]
help
Chatterbox?
[stevieb]: man, I absolutely LOVE driving in the worst winter conditions. In the mountainous roads, there are extremely few (if any) other drivers. I love the challenge. I've been doing extreme off-road my whole life, and as I said, I'm always well...
[stevieb]: ...prepared for even the very worst
Discipulus seems a part of the globe very unfrindly with Kawasaki riders..
[thezip]: My doggies love it when it snows
[perldigious]: As long as you are a good "boy scout" stevieb, more power to you... but I like my Jeep, and don't like the idea of rolling it or crashing it in to anything. :-)
[thezip]: Me, not as much.
[perldigious]: Mine too thezip, especially my German Shepherd. He looks like he is about to die of heat exhaustion all summer, so he goes nuts when winter comes and he can play in the snow.
[stevieb]: my main off-road vehicle nowadays is a strengthened mercedes ML320. I'm very hard on it, but I've never had any real issues at all (I love how small and light it is, and it has a very, very good centre of gravity for how I roll)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2016-12-06 16:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.