Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

How to change process title ?

by rumos (Novice)
on Oct 17, 2005 at 13:14 UTC ( #500714=perlquestion: print w/replies, xml ) Need Help??

rumos has asked for the wisdom of the Perl Monks concerning the following question:

Hello, ALL!
e.g. When I call "top" from bash - I see only "perl5.8.7" - But I want to see another information generated from my script.
Also - when somebody help me with this question - tell me - does my process description string must be equal in length to original (As I understand - this string saved somewhere in system memory and have already specified length (Of course it would be greate, if it's \0-terminated string with max length 255 chars) - so I can't overload it).
So - would be happy to get description how to get address of the process description string, and how can I write there.


Replies are listed 'Best First'.
Re: How to change process title ?
by blazar (Canon) on Oct 17, 2005 at 13:27 UTC
    I don't think people would call it "process title". Whatever, this is a faq; check in particular perldoc -q "perl's command line". To quote from it:
    To actually alter the visible command line, you can assign to the vari +- able $0 as documented in perlvar. This won't work on all operating systems, though.
    Appears to work:
    $ perl -e '$0="foo"; 1 while 1' & [1] 19748 $ ps U blazar PID TTY STAT TIME COMMAND 19585 ? S 0:00 sshd: blazar@pts/0 19592 pts/0 Ss 0:00 -bash 19748 pts/0 R 0:06 foo 19758 pts/0 R+ 0:00 ps U blazar

    Update: thanks to tirwhan for suggesting s/(?<=ps )aux | grep(?= blazar)/U/.

      I once spent a lot of time trying to change the process name on Solaris. I discovered that it depended on the version of ps you were using (BSD or not). It is highly system dependent.

        Indeed I originally read that particular faq while I were regularly on clpmisc, as individual faq entries were randomly posted there. Back then I felt intrigued by the possibility, and I tried it on Linux. I can't remember which {perl,kernel} version it was, but it didn't appear to work.

        Whatever, I don't know about other unices, but under Linux I guess that programs like ps just check /proc/$pid/cmdline, and I doubt (but I'm far from being sure!) that there are other ways to recover the same info.

        Now, as of my experiment of yesterday, it seems that at least with recent enough perls and kernels (5.8.7 and 2.6.13 respectively, here) assigning to $0 actually writes into /proc/self/cmdline:

        $ perl -le '$0="foo"; print <>' /proc/self/cmdline foo

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2023-02-01 03:52 GMT
Find Nodes?
    Voting Booth?

    No recent polls found