[tpm] fork and blessed hash references

Madison Kelly linux at alteeve.com
Thu Jan 14 07:39:46 PST 2010


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


More information about the toronto-pm mailing list