Subject: | verify should not fail when the program was started with low $ENV{COLUMNS} |
I asume the form until now has already included that my problem is with Proc::PID::File 1.24.
Perl version: v5.8.7 built for i386-linux-thread-multi
Operating System: Debian GNU/Linux; testing/unstable
The file that contains the module has the following line in it:
$Id: File.pm,v 1.16 2004/04/08 02:27:25 ekkis Exp $
Steps to reproduce:
# echo $COLUMNS
80
# cat > short-example-of-bad-verify.pl <<'EOF'
#! /usr/bin/perl
use strict;
use warnings;
use Proc::PID::File;
die "Already running!" if Proc::PID::File->running(verify => 1);
while (1) {
sleep 20;
}
EOF
# chmod +x short-example-of-bad-verify.pl
# ./short-example-of-bad-verify.pl&
# ./short-example-of-bad-verify.pl&
# pgrep short-ex
21481
21482
# echo Notice that there are now two processes running.
Notice that there are now two processes running.
# echo 'Maximize your terminal emulator!'
Maximize your terminal emulator!
# echo $COLUMNS
191
# ./short-example-of-bad-verify.pl
Already running! at ./short-example-of-bad-verify.pl line 7.
The reason for this is that `ps -fp $pid' adjusts its output to the width of the terminal resulting in no match for grep /$me/ unless $ENV{COLUMNS} is way high.
I had expected the second invocation of short-example-of-bad-verify.pl to fail stating "Already running!...".
"looking at /proc/$PID/stat for a process name" as suggested in the POD or possibly /proc/$PID/cmdline (at least at GNU/Linux) is probably a better solution than relying on ps.