SKIP: { skip("\$0 check only on Linux and FreeBSD", 2) unless $^O =~ /^(linux|freebsd)$/ && open CMDLINE, "/proc/$$/cmdline"; chomp(my $line = scalar ); my $me = (split /\0/, $line)[0]; is $me, $0, 'altering $0 is effective (testing with /proc/)'; close CMDLINE; # perlbug #22811 my $mydollarzero = sub { my($arg) = shift; $0 = $arg if defined $arg; # In FreeBSD the ps -o command= will cause # an empty header line, grab only the last line. my $ps = (`ps -o command= -p $$`)[-1]; return if $?; chomp $ps; printf "# 0[%s]ps[%s]\n", $0, $ps; $ps; }; my $ps = $mydollarzero->("x"); ok(!$ps # we allow that something goes wrong with the ps command