zentara wrote:
> On Thu, 30 Jun 2005 10:32:07 +0200, [EMAIL PROTECTED] (Tielman
> Koekemoer \) wrote:
> 
>>I have some subroutines that return information. Since the each
>>subroutine takes a snapshot of data on networked servers that should
>>be compared, I want the subroutines to execute in the shortest time
>>possible - I'd like to get all the subroutines running at the same
>>time. I thought of using fork() but I have not seen any code that
>>shows me how a forked process returns data to the parent process. And
> 
>>from what I've read in the Camel book, "everything else (except file
> 
>>descriptors) is copied" to the child process when fork()ed, so passing
>>the reference ta a hash will not work. But what if the child was
>>generating hashes and wanted to pass it to the parent?
>>
>>Q: How can I pass info (hashes / strings) from a child process to a
>>parent when the child is done processing?
> 
> 
> When you want to fork and return information, it is a good place to
> use threads and threads:shared.
> 
> If you are stuck with forking, you can 
> use pipes  (child writes to pipe, parent reads it)
> use sockets 
> use shared memory segments (probably the fastest, but trickier)
> write to a database
> write to a temp file
> 
[snip threads discussion]

If you are stuck with forking and need to do some of the above I would
switch to POE and let it handle the setting up of pipes and and the I/O.
Using its filters you can return arbitrarily structured data through
references (freeze/thaw model) or just simple strings (among others, or
write your own). POE::Wheel::Run will handle the fork, and you can pass
a subroutine for it to fork/exec just as you mentioned. POE has a
learning curve, a relatively steep one at that, but it will save you
time in the end.

http://poe.perl.org

Good luck,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to