1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
use warnings;
use Test::More;
use Data::Dumper;
BEGIN {
use_ok('Proc::ProcessTable');
}
SKIP: {
$0 = "PROC_PROCESSTABLE_TEST_CMD";
sleep(1);
my ($ps) = grep {/^$$\s+/} map { chomp; s/^\s*//; $_ } `ps xww`;
skip 'Cannot set process name', 1
unless ($ps && $ps =~ /PROC_PROCESSTABLE_TEST_CMD/);
# From Joelle Maslak: Can't set a process name to a blank name on
# OpenBSD, so this test is not relevant. From reading perlvar, it
# appears that this is likely true on other BSDs, so rather than
# looking for the OpenBSD operating system, we see if the command line
# starts with "perl:" as it does on OpenBSD (and presumably other
# BSDs). See OpenBSD's setproctitle(3) for information on what at
# least OpenBSD allows:
# https://man.openbsd.org/setproctitle.3
skip 'Likely *BSD system, can\'t blank process name', 1
unless ($ps =~ /^perl: /);
$SIG{CHLD} = 'IGNORE';
my $pid = fork;
die "cannot fork" unless defined $pid;
if ($pid == 0) {
#child
$0 = '';
sleep 10000;
} else {
#main
sleep 1;
my $t = Proc::ProcessTable->new;
my $cmnd_quoted = '';
my ($p) = grep { $_->{pid} == $pid } @{ $t->table };
is($p->{cmndline}, $cmnd_quoted, "odd process commandline bugfix ($cmnd_quoted)");
kill 9, $pid;
}
}
done_testing();
|