Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

How do I change my program's name under ps? ($0='abc' is messed up)

by entropy (Sexton)
on May 25, 2001 at 04:21 UTC ( [id://83181]=perlquestion: print w/replies, xml ) Need Help??

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

My goal is to change the process' name. According to the FAQ, I should just assign to the special $0 variable. This works a little, but the program's name now has four or five lines of spaces after it (when doing a 'ps axww'). Sometimes it works good, sometimes it doesn't. In fact, it seems that long values work, whereas shorter values have the spaces appended.
  • Comment on How do I change my program's name under ps? ($0='abc' is messed up)

Replies are listed 'Best First'.
Re: How do I change my program's name under ps? ($0='abc' is messed up)
by rpc (Monk) on May 25, 2001 at 04:37 UTC
    This is because when the process is created, the first argument is allocated to be the size of the actual process name. Try appending a \0 to your fake process name.
      \0 doesn't help on linux... On FreeBSD it seems to work with or without the \0 (in addition to displaying the original process name).

      If the memory is pre-allocated, then do I have to worry about overflowing it?

        Nope, you don't have to worry about overflowing it in Perl. You do however, when dealing with argv[0] in C, etc.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-04-23 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found