Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: perl vs she-bang perl

by tobyink (Abbot)
on Mar 06, 2013 at 22:45 UTC ( #1022113=note: print w/replies, xml ) Need Help??

in reply to perl vs she-bang perl

Devel::PL_origargv will tell you the arguments passed to Perl itself.

On Linux, I've not been able to figure out any official technique to determine whether or not the file was started via the shebang. If you go via /proc/$$/cmdline or similar, you just see a "rewritten" command line, so that a script started by typing ./ looks like perl ./

However, I have found an interesting heuristic that seems to work on my machine. If you read the 10th field from /proc/$$/stat (it's a number representing the number of minor page faults occurred during the running of the script), I've noticed it's about 25% higher when the script is run via a shebang.

Update:... hmm... interestinger and interestinger... I habitually use the shebang #!/usr/bin/env perl, but if you hard-code the path to the Perl executable (like #!/usr/bin/perl) then the second field of /proc/$$/stat is pretty clear.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: perl vs she-bang perl
by vsespb (Chaplain) on Mar 06, 2013 at 23:36 UTC
    Yep, #!/usr/bin/perl can be easy detected. It's even displayed differently in process list. As for /usr/bin/env - I suspect you can probably check parrent process and find its name?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022113]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-06-18 04:04 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.