in reply to 'better mousetrap': how to perform timed event
Why not just fork off a process to wait around and do the stuff?
# main loop while (1) { # do stuff # check for event my $event = check_for_event(); # now check for event and fork a child to deal with it # fork returns 0 to child, child PID to parent, undef if fails if ( $event and fork ==0 ) { # this is a child process sleep $whatever; do_stuff($event); # kid has done what was required so kill it exit 0; } # parent is continuing here, kid never gets here }
Obviously once check_for_event() has returned a true value for an event once you want to make sure it returns false for that event the next call or you will fork() your system to death. Depending on the frequency of events and the sleep time you can potentially have a steadily increasing burden of waiting kids build up.
Another option is to have a second parallel process to which you can send instructions. This process is in and endless loop waiting for instructions and executing them. You would probably pass it the instruction and an exec time which it stores in memory/file/DB and queries as required. Once an intruction has been processed you delete it.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: 'better mousetrap': how to perform timed event
by snafu (Chaplain) on Apr 23, 2003 at 06:35 UTC | |
by tachyon (Chancellor) on Apr 23, 2003 at 11:26 UTC | |
by snafu (Chaplain) on Apr 25, 2003 at 23:28 UTC | |
by tachyon (Chancellor) on Apr 26, 2003 at 12:29 UTC |