Changing python process name (or argv[0])
Juha Autero
Juha.Autero at iki.fi
Thu Jun 5 17:46:29 EDT 2003
"Daniel Fackrell" <newsgroups.NOSPAM at dfackrell.mailshell.com> 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 demo.py
#!/usr/bin/python
import time
print "Start of program"
time.sleep(120) # Give us time to check the process
print "End of program"
$ chmod u+x demo.py
$ ./demo.py &
[1] 6767
$ Start of program
$ ps
PID TTY TIME CMD
6762 pts/2 00:00:00 bash
6767 pts/2 00:00:00 demo.py
6768 pts/2 00:00:00 ps
$ End of program
[1]+ Done ./demo.py
$
It's not portable to other operating systems, but neither is argv
mugging.
--
Juha Autero
http://www.iki.fi/jautero/
Eschew obscurity!
More information about the Python-list
mailing list