[tpm] fork and blessed hash references

Indy Singh indy at indigostar.com
Thu Jan 14 08:01:43 PST 2010


> 2. What is the best way to "share" variables between children and 
> parents?
Have a look at 'perldoc perlipc'

> 1. Why do the self references match when they don't (apparently) use 
> the same memory space
The two processes use the same logical memory address, but it gets 
mapped to a differnt physical address.  This way the processes are 
protected from each other.  If you really wanted to share memory you 
would have to call the memory sharing functions provided by the OS.  No 
sure how to do that from Perl, or if it is even worth the trouble.

Indy Singh
IndigoSTAR Software -- www.indigostar.com

----- Original Message ----- 
From: "Madison Kelly" <linux at alteeve.com>
To: "Toronto Perl Mongers" <tpm at to.pm.org>
Sent: Thursday, January 14, 2010 10:39 AM
Subject: [tpm] fork and blessed hash references


> Hi all,
>
>   I want to put a shutdown timer on a spawnable daemon (specifically, 
> a script spawned by dbus). To do this, I created a bless'ed "self" 
> hash reference in my module's constructor, set a few time values in it 
> and the call a timer method. In the timer method, I 'fork' and the 
> child starts a loop and the main script returns and waits for method 
> calls over dbus.
>
>   The problem is that, in the child process, changes to the values in 
> 'self' made by the parent do not appear in the child. Specifically, 
> each method call changes a '$self->{SHUTDOWN_TIME}' value. I can 
> understand this behavior to an extent, but when I print out the hash 
> reference itself both in the parent and the child, they have the same 
> reference string. Obviously though, they aren't actually using the 
> same memory space.
>
>   So two questions;
>
> 1. Why do the self references match when they don't (apparently) use 
> the same memory space
>
> 2. What is the best way to "share" variables between children and 
> parents?
>
>   Currently I am working around the problem by writing out my timing 
> info to a tmp file, but this seems to be unnecessarily expensive.
>
> Thanks all!
>
> Madi
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm 



More information about the toronto-pm mailing list