eastcoastcoder has asked for the wisdom of the Perl Monks concerning the following question:
I have a Perl mini daemon that I would like to control as follows:
1) The daemon consists of a loop, which loops until either a counter is reached, or a TERM signal is received
2) When either of those happen, it waits till it finishes the current loop, then exits.
Number 2 does not seem to happen
Here is my code:
Why no work?use constant MAX_ITERATIONS => 1000; use constant MAX_TIME => 600; use warnings; use strict; my $start_time = time; my $iterations = 0; my $exit_requested = 0; my $handling_request = 0; sub sig_handler { $exit_requested = 1; exit(0) if !$handling_request; } $SIG{TERM} = \&sig_handler; init(); while (!$exit_requested && $iterations <= MAX_ITERATIONS && (time - $s +tart_time) < MAX_TIME) { $handling_request = 1; handle_request(); $iterations++; $handling_request = 0; } exit(0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Controlling a Perl Daemon with Signals
by sk (Curate) on Aug 05, 2005 at 21:46 UTC | |
by eastcoastcoder (Sexton) on Aug 05, 2005 at 22:30 UTC | |
by sk (Curate) on Aug 06, 2005 at 04:15 UTC | |
by jch341277 (Sexton) on Aug 08, 2005 at 14:44 UTC | |
|
Re: Controlling a Perl Daemon with Signals
by jch341277 (Sexton) on Aug 05, 2005 at 21:49 UTC | |
by eastcoastcoder (Sexton) on Aug 05, 2005 at 22:32 UTC | |
by eastcoastcoder (Sexton) on Aug 05, 2005 at 23:52 UTC | |
by jch341277 (Sexton) on Aug 08, 2005 at 15:27 UTC |