Changing python process name (or argv[0])

mike wakerly mike-list at wakerly.com
Wed Jun 4 02:24:41 EDT 2003


Hello All,

Last summer, Dave Cinege submitted a small module that allowed editing of argv 
-- particularly useful when you would like to change argv[0], the name of the 
process (as seen by ps and others.) The details of it can be found here:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=mailman.1027382614.7327.python-list%40python.org&rnum=1

(I've also quoted the message below.)

I am using metalog on my system, and my python bits use the syslog module. 
Unfortunately, in a vanilla setup, this causes metalog to print '[python]' as 
the reporting process's name; ideally, I wanted syslog to show the script's 
name, or even a user-defined process name.

My question for the list is this: might the functionality that Dave's module 
provides be incorporated into Python anytime soon? Perhaps some might see 
modifying argv as a 'hack'; I think the functionality is desirable for some 
(at least on Unix python), and this simple trick hardly warrants an extra 
module if it is indeed acceptable in the python world. It seems that Mr. 
Cinege has been looking for this ability to be inbuilt for quite some time..

As an aside, if anyone can suggest a way to trick metalog (within python or 
otherwise) into reporting a different program name, I am also interested in 
that.

Cheers,
Mike Wakerly


On Mon, 22 Jul 2002 20:00:55 -0400, Dave Cinege <dcinege at psychosis.com> wrote:
> keyphrases:
> setproctitle proctitle
> change process name
> change process title
> change ps output 
> argv[0] argv[-1]
> 
> It was about a year ago, I produced a nasty patch to sys that allowed
> changing the raw argv[] of the python process. 
> 
> A year later its sad this functionality has *still* not be intergrated
> into Python itself.  : <
> 
> In linux this modules allows one to change the output seen from 'ps'.
> (And the processes 'cmdline' in /proc/)
> It is useful for hiding 'python', an argument that is a password,
> or update process information.
> 
> The joy of unempoyment has given me the time to rewrite my patch as
> a stand alone module. The module is by no means done. I need people
> to test on platforms other then Linux and provides results.
> 
> Once it has been made portable, I intend to talk to Guido about how
> he'd like to see this intergrated into Python, and then do so.
> It would likely become an extension to the posix module.
> 
> Please DL from:
>  http://ftp.psychosis.com/python/
>  ftp://ftp.psychosis.com/python/
> 
> 
> An idea how it currently works:
> 
>  import proctitle
>  Argv = proctitle.ProcTitle()
> 
>  print 'Saving Original argv[]'
>  Argv.save()
>  print 'argv[0:2]: ', Argv[0:2]
>  print Argv
> 
>  Argv[0] = 'Python - Why use anything else?'
>  Argv[0:] = 'Python - Why use anything else?'
> 
>  print 'Slide argv args back one. (hide "python")'
>  print 'Process line now matches sys.argv'
>  Argv[0:] = string.join(Argv[1:]).replace(',','')
> 
>  print 'Restoring Original argv[]'
>  Argv.restore()






More information about the Python-list mailing list