Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Re: Re: Re: Re: 'better mousetrap': how to perform timed event

by tachyon (Chancellor)
on Apr 26, 2003 at 12:29 UTC ( #253349=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Re: 'better mousetrap': how to perform timed event
in thread 'better mousetrap': how to perform timed event

However, forked children don't know what their parent is doing nor does the parent know what it's children are doing with the exception of when the child exits, right?

This is totally wrong. Read perlipc

Here is code that uses Hang Up signal to perform the required parent/child IPC:

[root@id3 root]# cat #!/usr/bin/perl $|++; $SIG{HUP} = sub { do_end_vote() }; while ( 1 ) { my $event = check_for_event(); if ( $event ) { do_start_vote(); if ( fork() == 0 ) { # this is kid sleep 10; local $SIG{HUP} = sub { print "Child caught HUP!" }; # signal parent (and kid) kill HUP, $0; exit 0; } } # this is parent sleep 1; print "."; } sub do_start_vote { print "Begin" } sub do_end_vote{ print "End!" } # generate one event every 20 calls to this sub for testing sub check_for_event{ $a++; return $a%20 == 0 ? 1 : 0 } [root@id3 root]# ./ ...................Begin.........Child caught HUP!End!...........Begin +.........Child caught HUP!End!...........Begin.... [root@id3 root]#




  • Comment on Re: Re: Re: Re: Re: 'better mousetrap': how to perform timed event
  • Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://253349]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2021-06-13 15:28 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (57 votes). Check out past polls.