Marcelo Fernández <fernandez...@yahoo.com.ar> added the comment:

This patch (to python 2.7 trunk) allows to call prctl() function from
Linux kernel to change the process name. It adds two methods to the os
module: os.getprocname() and os.setprocname().

Working example:

marc...@marcelo-laptop:~/src/pytrunk$ ./python
Python 2.7a0 (trunk:71261M, Apr  5 2009, 16:32:55)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
[34831 refs]
>>> os.getprocname()
'./python'
[34833 refs]
>>> os.getpid()
5601
[34833 refs]
>>> os.setprocname('hello_process_name')
[34833 refs]
>>> os.getprocname()
'hello_process_name'
[34833 refs]

Before changing the process name:
marc...@marcelo-laptop:~/src/pytrunk$ ps -fax | grep 5601
Warning: bad ps syntax, perhaps a bogus '-'? See
http://procps.sf.net/faq.html
 5601 pts/2    S+     0:00  |   \_ ./python
 5611 pts/3    S+     0:00      \_ grep 5601

After changing the process name:
marc...@marcelo-laptop:~/src/pytrunk$ ps -fax | grep 5601
Warning: bad ps syntax, perhaps a bogus '-'? See
http://procps.sf.net/faq.html
 5601 pts/2    S+     0:00  |   \_ hello_process_name
 5635 pts/3    S+     0:00      \_ grep 5601

And "killall hello_process_name" works, Gnome Process monitor shows it
fine too. By now this is Linux only, but I hope to implement it also for
BSD (FreeBSD has it[1], OpenBSD [2] and NetBSD [3] too).

[1] http://fxr.watson.org/fxr/source/gen/setproctitle.c?v=FREEBSD-LIBC
[2]
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/gen/setproctitle.c?rev=1.11;content-type=text%2Fx-cvsweb-markup
[3]
http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setproctitle.c?rev=1.22&content-type=text/x-cvsweb-markup&only_with_tag=MAIN

Regards

----------
keywords: +patch
Added file: http://bugs.python.org/file13635/issue5672_1.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5672>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to