slydog has asked for the wisdom of the Perl Monks concerning the following question:
and the processing mod:#!/usr/bin/perl use mxMSsmtp::Config; use mxMSsmtp::Run; use Getopt::Std; use strict; my %opts; my $cfg = undef; my $pid; getopts('c:D', \%opts); $cfg = $opts{c} if $opts{c}; my $vars = mxMSsmtp::Config::get($cfg) or die "Problem getting config +file\n"; if ($opts{D}) { run mxMSsmtp::Run($vars) unless $pid = fork; } else { run mxMSsmtp::Run($vars); } exit;
package mxMSsmtp::Run; use Symbol; use POSIX; use strict; my %children = (); my $children = 0; sub _REAPER { $SIG{CHLD} = \&_REAPER; my $pid = wait; $children--; delete $children{$pid}; } sub _KILLER { local($SIG{CHLD}) = 'IGNORE'; kill 'INT' => keys %children; exit; } sub run { my ($me, $vars) = @_; my $preFork = $vars->{preFork}; for (1 .. $preFork) { _startCHLD($vars); } $SIG{CHLD} = \&_REAPER; $SIG{INT} = \&_KILLER; while (1) { sleep; for (my $i = $children; $i < $preFork; $i++) { _startCHLD($vars); } } } sub _startCHLD { my ($vars) = @_; my $pid; my $sigset; $sigset = POSIX::SigSet->new(SIGINT); sigprocmask(SIG_BLOCK, $sigset) or die $!; die $! unless defined ($pid = fork); if ($pid) { # Parent process sigprocmask(SIG_UNBLOCK, $sigset) or die $!; $children{$pid} = 1; $children++; return; } else { # Child Process $SIG{INT} = 'DEFAULT'; sigprocmask(SIG_UNBLOCK, $sigset) or die $!; for (my $i = 0; $i < $vars->{maxClients}; $i++) { print "$i\n"; sleep(10); } exit; } } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reaping Child procs causing <defunct>????
by Abigail-II (Bishop) on May 14, 2003 at 23:20 UTC |