[tpm] fork and blessed hash references

Madison Kelly linux at alteeve.com
Thu Jan 14 08:16:55 PST 2010

Fulko Hew wrote:
>      So two questions;
>     1. Why do the self references match when they don't (apparently) use
>     the same memory space
> Because a forked process contains a 'copy' of the parent process.  Since 
> its an exact copy, it
> effectively has exactly the same memory addresses. (but they are in a 
> separate instance of memory space)
>     2. What is the best way to "share" variables between children and
>     parents?
> Pipes, shared memory, files, sockets, etc.  There is no 'best' way.
> Originally forked process (parent/child) were intended to be 'very 
> independent'
> and hence don't 'share memory', and are protected from the other's 'bugs',
> and your only choices are the ones above.
> Then the world invented threads, where everything runs in the same 
> process space
> and effectively shares everything, were one thread can accidentally 
> (bug) walk over
> everything.
>     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 Fulko!

   I didn't realize that the "copy" duplicated what looked to me to be 
memory addresses while not actually being so.

   I ran this by my boss after sending this (it's not a work project, 
but he's a geek enough to take interest). He suggested posix's settimer, 
which perl doesn't seem to implement. However, that led us to 'alarm', 
which might just be the ticket.

   The idea is; Setup a SIGALARM handler that shuts down the daemon, 
then on setup set an alarm for X time in the future. After that, each 
method call can call 'alarm' for Y time in the future, hopefully 
clearing the current pending alarm(s) and pushing the back into the 
future. Once there is enough time with no activity, the SIGALARM will 
call the handler and will shut down the daemon.

   This should let me stay in the same memory space without the risks of 
threading while leaving the daemon ready to respond to method calls. 
Think this should work?

   Every day, something new to learn. I love this stuff. :3


More information about the toronto-pm mailing list