Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by snafu (Chaplain)
on Apr 23, 2003 at 06:35 UTC ( [id://252463]=note: print w/replies, xml ) Need Help??


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

I thought of this approach but wasn't able to come up with a really good way for the parent to know when the child finished counting. I am guessing that I would perform something to find out when the child is reaped (supposing it exits when the timer is finished?).

I apologize for some of the misunderstanding. This goes into somethings that have never been quite clear to me.

_ _ _ _ _ _ _ _ _ _
- Jim
Insert clever comment here...

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

Replies are listed 'Best First'.
Re: Re: Re: 'better mousetrap': how to perform timed event
by tachyon (Chancellor) on Apr 23, 2003 at 11:26 UTC

    You can find out exactly when the child exits but this is not what you specified which was exec something X seconds after Y event occurs. Forking a kid will do that for you and is quite portable. Why do you need to know when the child finishes? Not in spec. Kid will do its stuff X seconds after Y event. Why monitor it? What would you do if the child failed? If nothing redo Does it really matter? If no redo. What is failure? etc.....

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      I don't need to exec() something as much as I need to call a sub-routine. I would figure that since the fork()'ed child is monitoring the time difference it probably couldn't call the sub-routine once the timelimit was reached, right? If I were using threads this could be possible, iiuc. 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? Im not trying to be snide. I'm honestly asking the question because this is how I understand how it all works.

      So, in short, after 20 seconds once the vote has been initiated, I need to call end_vote() which does some things and then re-initializes all the variables used in the vote session.

      _ _ _ _ _ _ _ _ _ _
      - Jim
      Insert clever comment here...

        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 test.pl #!/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]# ./test.pl ...................Begin.........Child caught HUP!End!...........Begin +.........Child caught HUP!End!...........Begin.... [root@id3 root]#

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-18 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found