Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Changing $0 under solaris

by gnu@perl (Pilgrim)
on May 20, 2004 at 17:08 UTC ( #355018=perlquestion: print w/replies, xml ) Need Help??

gnu@perl has asked for the wisdom of the Perl Monks concerning the following question:

I have the need to display different information under the 'ps -ef' output. I have tried simply setting $0='my_new_name'; but this has no effect. I looked here 83181 but it did not offer any further information

I have tried making a small program which sets $0 and then forks to see if the child would pick up the new $0, but no such luck, still just displays (/usr/bin/perl -w ./ ).

This makes sense because the process table is populated with the process information before the program is evaluated, but does anyone know of a way to do this under Solaris 8?

Any Ideas?


Replies are listed 'Best First'.
Re: Changing $0 under solaris
by Nitrox (Chaplain) on May 20, 2004 at 17:44 UTC
    You can't under Solaris. The 'ps' command reads the process table from kernel space, not user space like on Linux.


      That's what I figured (and what the evidence points to). Thanks.
Re: Changing $0 under solaris
by JSchmitz (Canon) on May 20, 2004 at 18:18 UTC
    if you want quick and dirty there are some really good alternate ps type scripts here that may give you some really good ideas. You may also want to play with prstat.

Re: Changing $0 under solaris
by Plankton (Vicar) on May 20, 2004 at 20:58 UTC
    Why not just call your script my_new_name then when you do a ps you'll see /usr/bin/perl -s ./my_new_name if you don't want to see the /usr/bin/perl why not just do cp /usr/bin/perl /usr/bin/somethingelse and change your shebang to run with /usr/bin/somethingelse?

    Plankton: 1% Evil, 99% Hot Gas.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://355018]
Approved by davido
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2023-06-10 00:00 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (36 votes). Check out past polls.