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

Re: Perl fork childs with variables

by rjt (Deacon)
on Mar 07, 2013 at 01:02 UTC ( #1022127=note: print w/replies, xml ) Need Help??

in reply to Perl fork childs with variables

Hello Stefan!

The thing with a fork()'d model is that the operating system is creating two additional and separate processes. While they initially have (nearly) the same state as the parent, they are in fact separate, and any changes to memory (i.e., variables) in one will have no effect on the other processes, just as you would expect with any other distinct process.

All is not lost: you will need to use some form of inter-process communication (IPC) to allow your processes to communicate their results to the parent. If you are in a POSIX environment (likely, if you are using fork()), you might have a look at IPC::SysV and IPC::Msg for a start, and do some searching on for other IPC modules best suited to what you need to do.

Finally, is there a special reason you actually need a fork()'d model in the first place? Can you use threads instead? Perl's threads implementation makes shared variables and semaphores between threads very easy.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022127]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-03-21 10:02 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (265 votes). Check out past polls.