Changing python process name (or argv[0])

Juha Autero Juha.Autero at
Thu Jun 5 23:46:29 CEST 2003

"Daniel Fackrell" <newsgroups.NOSPAM at> writes:

> Hrm... maybe I'm just naive on this point, but it seems to me that having
> python programs show up by name is ps, top, etc. would be a nice benefit,
> especially where many different python processes might be running
> simultaneously.  I'd even consider that such should be the default. 

There is a rather standard way to achieve that in UN*X. Make the file
executable and use shebang to specify python interpreter:

$ cat
import time
print "Start of program"
time.sleep(120) # Give us time to check the process
print "End of program"
$ chmod u+x
$ ./ &
[1] 6767
$ Start of program

$ ps
  PID TTY          TIME CMD
 6762 pts/2    00:00:00 bash
 6767 pts/2    00:00:00
 6768 pts/2    00:00:00 ps
$ End of program

[1]+  Done                    ./

It's not portable to other operating systems, but neither is argv

Juha Autero
Eschew obscurity!

More information about the Python-list mailing list