Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl脚本在Linux box上返回错误的僵尸进程输出_Perl - Fatal编程技术网

Perl脚本在Linux box上返回错误的僵尸进程输出

Perl脚本在Linux box上返回错误的僵尸进程输出,perl,Perl,Perl脚本在Linux box上返回的zomibie进程值不正确 my $threshold = 5; $number_of_defuncts = `ps -ef | grep defunct |grep -v grep|wc -l`; if ( $number_of_defuncts > $threshold ) { print("number of defunct is [$number_of_defuncts] \n");

Perl脚本在Linux box上返回的zomibie进程值不正确

    my $threshold = 5;

    $number_of_defuncts = `ps -ef | grep defunct |grep -v grep|wc -l`;
    if ( $number_of_defuncts > $threshold )
    {
            print("number of defunct is [$number_of_defuncts] \n");
    }
当通过ps命令手动检查时,僵尸进程始终为零,但使用perl脚本会给出错误的7、8或类似的高数字输出。

(仅限linux)


[1] 不,
ps-ef
也不是可移植的。

提示:要避免
grep
发现自己,请使用
grep“[d]efunct”
代替,使用其中一种方法来避免次要的
grep-v
。没有更多的系统/代码上下文,很难知道。你能不能给我们看一下ps-ef | grepde[f]unct | wc-l的输出,然后再从同一个shell的提示符显示
perl-E'say`ps-ef | grepde[f]unct | wc-l`
$zombie_count = do { local *ARGV; @ARGV=</proc/[0-9]*/stat>; grep /Z[^)]*$/, <> }
$ perl -e 'my $pid = open my $fh, "echo yup|"; exec "ps", $pid'
  PID TTY      STAT   TIME COMMAND
 6840 pts/11   Z+     0:00 [echo] <defunct>
$ perl -e 'my $pid = open my $fh, "echo yup|"; undef $fh; exec "ps", $pid'
  PID TTY      STAT   TIME COMMAND
$ perl -e 'my $pid = open my $fh, "echo yup|"; wait; exec "ps", $pid'
  PID TTY      STAT   TIME COMMAND
$ perl -e 'my $pid = open FH, "echo yup|"; close FH; exec "ps", $pid'
  PID TTY      STAT   TIME COMMAND