Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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 http://www.cpan.org 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.


Comment on Re: Perl fork childs with variables
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022127]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-07-10 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (198 votes), past polls