woosley has asked for the wisdom of the Perl Monks concerning the following question:

hi all, I need to run a interactive perl script on the remote machine so I followed the code at http://poe.perl.org/?POE_Cookbook/Job_Server to wrote a poe job server, I got the script to run except one problem:
] when I finished the "perlit" which is a script asking me for the username and password here, the child process created by POE::Wheel::Run just went into the status of "zombie", which mean that it was not reaped by the parent process, dose any one know the reason for this?
below is the code
use POE qw/Component::Server::TCP Wheel::Run/; *POE::Kernel::USE_SIGCHLD = sub (){1}; $SIG{CHLD} = 'ignore'; my %program = ( time => '/bin/date', perlit => 'perl get_name.pl', ); POE::Component::Server::TCP->new( Alias => 'Job Server', Port => 32080, ClientConnected => sub { $_[KERNEL]->yield('usage'); }, ClientDisconnected => sub { delete $_[HEAP]->{job}; }, ClientInput => sub { my ($heap, $input) = @_[HEAP, ARG0]; if ($heap->{job}) { $heap->{job}->put($input); return; } my $program = $program{$input}; unless (defined $program) { $_[KERNEL]->yield('usage'); return; } $heap->{job} = POE::Wheel::Run->new( Program => $program, StdioFilter => POE::Filter::Line->new(), StderrFilter => POE::Filter::Line->new(), Conduit => 'pty', StdoutEvent => 'got_job_stdout', StderrEvent => 'got_job_stderr', CloseEvent => 'got_job_close', ); $heap->{client}->put('Job' . $heap->{job}->PID . 'Started'); }, InlineStates => { got_job_stdout => sub { my $heap = $_[HEAP]; $heap->{client}->put($_[ARG0]); }, got_job_stderr => sub { my $heap = $_[HEAP]; $heap->{client}->put('ERR' . $_[ARG0]); }, got_job_close => sub { my ($heap, $kernel) = @_[HEAP, KERNEL]; my $job = delete $heap->{job}; $heap->{client}->put('Job' . $job->PID . ' Stopped'); }, usage => sub { my @commands = sort keys %program; $_[HEAP]->{client}->put("Commands : @commands"); }, } ); $poe_kernel->run();

Replies are listed 'Best First'.
Re: child reap in poe?
by Joost (Canon) on Sep 28, 2009 at 11:53 UTC
    Any option constants like USE_SIGCHLD must be used before the use POE statement. Also, it's generally a bad idea to try and remove control of reaping from POE (i.e. by setting SIGCHLD to IGNORE). In the case of POE::Wheel::Run, you should use the $kernel->sig_child method to make sure you clean up after a child exit (basically, delete the wheel). See the SYNOPSIS section of POE::Wheel::Run for an example.