Perl脚本在Linux box上返回错误的僵尸进程输出
Perl脚本在Linux box上返回的zomibie进程值不正确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");
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