<div>Thanks for the info Ben -> I browsed the Catalyst source via the <a href="http://cpan.org">cpan.org</a>, but couldn't find any calls to $0... (I dont really want to install every Catalyst module.... just to grep the source...).</div>

<div><br></div><div>I know some other software that uses it, eg: MySQLRelicationClient.pl</div><div><br></div><div><br></div><div>So just as a follow up to this thread, here is the code that I execute (via loading the "Lib.pm" module) for every script that I write:</div>

<div><br></div><div>package Lib;</div><div>....</div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">use Cwd qw( cwd abs_path chdir );</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">

use File::Basename;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">use File::Spec;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">

our $BASENAME;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">our $DIRNAME;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">

our $BASEPATH;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">BEGIN {</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">

  $BASENAME = basename($0);</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">  $BASEPATH = abs_path(dirname($0)) || "";</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">

  $DIRNAME = $0 =~ /^\// ? dirname($0) : $ENV{PWD}."/".$0;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">  $DIRNAME =~ s/\/?\w+\/\.\.\//\//g;</div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">}</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">

use lib $BASEPATH;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">$0 = "$BASEPATH/$BASENAME".(@ARGV == 0 ? "" : " ".join(" ",@ARGV));</div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">use Sys::Prctl;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">

Sys::Prctl::prctl_name($BASENAME);</div>...</div><div>1;</div><div><br></div><div><br></div><div>Ignoring the globals, this sets $0 to something useful for top/ps/pidof/killall.</div><div><br></div><div>regards,</div><div>

Mathew</div><div><br></div><br><div class="gmail_quote">On 18 July 2012 01:26, Ben Hare <span dir="ltr"><<a href="mailto:benhare@gmail.com" target="_blank">benhare@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hey Mat and yes I'm still Perling..! :)<br>
<br>
I like what Catalyst is doing regarding this. Maybe have a look at<br>
that project if you haven't already.<br>
<br>
NOTE: Below examples all relate to FastCGI implementations of Catalyst.<br>
<br>
* Older versions made the script name show in top but not in ps ( ps<br>
would just show 'perl', top would show 'script.cgi' ).<br>
* The latest version does the reverse and will just show 'perl' in top<br>
but in ps:<br>
<br>
'perl-fcgi-pm [Xtapes]'<br>
<br>
the [<app_name>] indicating each app's name as defined in Catalyst config.<br>
<br>
I like this approach ( as long as the processes are running as<br>
different users, you know what it is in top anyway ).<br>
<br>
Some more ideas ( It's 00:55 and I'm too lazy to look at *how* they're<br>
doing it sorry - exercise for reader :) ).<br>
<br>
Ben.<br>
<br>
<br>
On 16 July 2012 14:50, Mathew Robertson<br>
<div><div class="h5"><<a href="mailto:mathew.blair.robertson@gmail.com">mathew.blair.robertson@gmail.com</a>> wrote:<br>
> Hi list,<br>
><br>
> I having been having some quirky behaviour when assigning $0...<br>
> For me this turned out to be as a result from this:<br>
><br>
> $0 = abs_path(dirname($0))."/".basename($0);<br>
><br>
> ie: make the process name (as shown in top/ps, be the name of the script -<br>
> instead of the perl binary.<br>
> Which worked well when running "pidof <a href="http://whatever.pl" target="_blank">whatever.pl</a>", "ps auxww | grep<br>
> <a href="http://whatever.pl" target="_blank">whatever.pl</a>", but not so much for "killall <a href="http://whatever.pl" target="_blank">whatever.pl</a>".<br>
><br>
> Some Googling has turned up the problem/cause:<br>
> <a href="http://blogs.perl.org/users/aevar_arnfjor_bjarmason/2010/03/what-happens-when-you-assign-to-0.html" target="_blank">http://blogs.perl.org/users/aevar_arnfjor_bjarmason/2010/03/what-happens-when-you-assign-to-0.html</a><br>


><br>
> perl version is: v5.14.2<br>
><br>
><br>
> So I run the example shown -> which shows that the patch is applied.  Upon<br>
> further investigation, I think the implementation could be refined, ie: in<br>
> my code above, only the first 16 characters of string are chomped, thus<br>
> leaving the program title with part of the the basepath of the script. In my<br>
> case I worked around it using Sys::Prtcl->prctl_name($BASENAME),<br>
><br>
><br>
> The suggested change to this enhancement would be, if $0 points at a script,<br>
> then change $0 assignment so that Perl grok's the rightmost part of the<br>
> path. ie: leave $0 as-is, but modify this patch as so.<br>
><br>
> Thoughts?<br>
> Mathew<br>
><br>
</div></div>> _______________________________________________<br>
> Melbourne-pm mailing list<br>
> <a href="mailto:Melbourne-pm@pm.org">Melbourne-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Ben Hare<br>
Professional Web Development Services<br>
ABN: 22-48-55-71-887<br>
Phone: <a href="tel:%2B61-415-607-197" value="+61415607197">+61-415-607-197</a><br>
Web: <a href="http://www.benhare.com" target="_blank">http://www.benhare.com</a><br>
Email: <a href="mailto:ben@benhare.com">ben@benhare.com</a><br>
</font></span></blockquote></div><br>