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

Re: hash elements are lost during reaping

by Anonymous Monk
on Dec 11, 2012 at 11:10 UTC ( #1008264=note: print w/replies, xml ) Need Help??

in reply to hash elements are lost during reaping

What am I doing wrong here?

You're assuming its the same hash , print out the reference and you'll see that its different,  warn \%TrappedPIDs;

But I'm guessing as you don't show the forking part

:)Mr. Peabody Explains fork()

Replies are listed 'Best First'.
Re^2: hash elements are lost during reaping
by umitd (Initiate) on Dec 11, 2012 at 11:30 UTC

    Thanks for the reply. My fork routine saves pids of children in another hash to be compared in the processing routine:

    sub StartJob { my $pid; my $sid = shift; FORK: { if ($pid = fork) { # # This is the dispatcher! # $JobPIDs{$pid} = $sid; # add pid, sid pair to th +e hash } elsif ($pid == 0) { ....

    The processing routine goes like this:

    foreach $pid ( keys(%TrappedPIDs) ) { $rc = $TrappedPIDs{$pid}; print " CHECKING: trapped pid: $pid RC: $rc \n"; if ( exists($JobPIDs{$pid}) and $rc == 0 ) { # do the processing .. }
    %TrappedPIDs is a global hash. How come it can be different?


      How come it can be different?

      With you showing only small code fragments, it's rather hard to say. It's kind of like the old joke:

      Goofus is searching for his diamond ring under a streetlamp.

      Gallant comes to help, and after about 15 minutes, he says "Hey--about where were you standing when you lost the ring?".

      Goofus: "Over there in the parking lot."

      Gallant (surprised): "Well, then why are you looking over here?"

      Goofus: "The light is better."


      When your only tool is a hammer, all problems look like your thumb.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008264]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2018-06-24 19:15 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.