What happens when you assign to $0?

According to git log I've submitted 33 patches to perl core, I just submitted another one which on Linux changes this:

Into this:

If this patch gets applied doing killall onion on 5.14 will get you a dead process instead of onion: no process found, the same goes for ps(1) and top(1) which read the legacy process name by default. Before this patch the behavior of $0 assignment on Linux hadn't changed since perl 4.000 came out.

4 Comments

According to perlvar:

'If the program has been given to perl via the switches -e or -E , $0 will contain the string "-e" .'

How come in the above onion-5.12.txt output the "perl" line doesn't read "perl -e"?

How come in the above onion-5.12.txt output the "perl" line doesn't read "perl -e"?<<

Because the "perl" returned by "ps hc $$" has no relation to $0, which is the whole issue here. The legacy process name is "perl" because the name of the executable file is "perl". If he had put this in a script called foo.pl and executed it via "./foo.pl", the legacy process name would be "foo.pl".

Leave a comment

About Ævar Arnfjörð Bjarmason

user-pic Blogging about anything Perl-related I get up to.