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

Problem is that i get zombies..... The main Program must run because it runs as a daemon so i can't exit it to cleanup my zombie prozesses........ ps aux |grep Z USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 307 0.0 0.0 0 0 pts/1 Z+ 19:27 0:00 a2.pl <defunct> root 319 0.0 0.0 0 0 pts/1 Z+ 19:27 0:00 a2.pl <defunct> root 324 0.0 0.0 0 0 pts/1 Z+ 19:28 0:00 a2.pl <defunct> root 334 0.0 0.0 0 0 pts/1 Z+ 19:28 0:00 a2.pl <defunct> root 353 0.1 0.0 0 0 pts/1 Z+ 19:28 0:00 a2.pl <defunct> root 381 0.0 0.0 0 0 pts/1 Z+ 19:28 0:00 a2.pl <defunct> root 404 0.2 0.0 0 0 pts/1 Z+ 19:28 0:00 a2.pl <defunct> root 421 0.0 0.0 9852 872 pts/2 S+ 19:28 0:00 grep Z

Main Perl String #!/usr/bin/perl -w use strict; use warnings; use IPC::Cmd qw[can_run run run_forked]; my $timeout = 1; my $erg; my $cmd='/home/a2.pl'; while(1){ if( scalar run( command => $cmd, verbose => 0, buffer => \$erg +, timeout => $timeout )){ print 'success:'.$erg."\n"; }else{ if(!$erg){ $erg='ERROR'; } print 'timeout cmd:'.$cmd.' ergr='.$erg."\n"; } sleep(5); } 1; /home/a2.pl #!/usr/bin/perl print 10000; #print 'or some text.....'; 1;
  • Comment on Function for Timing out shell commands without getting Zombie Prozesses
  • Download Code

Replies are listed 'Best First'.
Re: Function for Timing out shell commands without getting Zombie Prozesses
by zentara (Cardinal) on Sep 15, 2011 at 18:46 UTC
Re: Function for Timing out shell commands without getting Zombie Prozesses
by BrowserUk (Patriarch) on Sep 15, 2011 at 17:44 UTC

    See in timedCommand() in Re^3: Backticks and SIGALRM.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      don't work, getting Can't kill a non-numeric process ID at ./t.pl line 36.

      don't work, getting Can't kill a non-numeric process ID at ./t.pl line 36.

        Can't kill a non-numeric process ID at ./t.pl line 36.

        Being as the script I linked to only has 35 lines, you must have changed something.

        Given the reference to "kill", it would have to be one of these two lines producing the error:

        kill 0, $pid while sleep 1 and $timeout--; kill 3, $pid and return if $timeout;

        And given that $pid is set by this line:

        $pid = open my $fh, "$cmd |" or die "$!, $^E";

        it can only take a numeric value or undef. If it was undef, due to the command failing to run, then the die would have prevented the code reaching the kill lines.

        So, what did you change and why?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Function for Timing out shell commands without getting Zombie Prozesses
by eyepopslikeamosquito (Archbishop) on Sep 16, 2011 at 02:16 UTC