in reply to How to change process title ?

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/.

Replies are listed 'Best First'.
Re^2: How to change process title ?
by mescanne (Sexton) on Oct 17, 2005 at 15:37 UTC
    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.

    Mark
      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