[issue5672] Implement a way to change the python process name

Daniele Varrazzo report at bugs.python.org
Sun Dec 6 20:11:13 CET 2009


Daniele Varrazzo <piro at develer.com> added the comment:

> I'm taking a look at it, and it seems to use setproctitle() in BSD, 
and 
> writes over the argv array "in most Sys-V like systems"; this 
includes 
> Linux?

Yes: Linux uses what in the source is referred as the 
PS_USE_CLOBBER_ARGV strategy: it writes over the area pointed by argv 
and by environ (after checked they are contiguous and moved away). 
Sounds scary, but I've tested that environ keeps working fine (the 
environ can be modified and forked processes receive the correct 
environment).

> My question is because I think there's a better and supported method 
for 
> Linux, that is, using prctl [1]. I read somewhere that changing argv 
> causes some inconsistencies between programs who read /sys files, 
/proc 
> files... or I don't remember what, but it is, in fact, not the 
> *recommended* way. Prctl is. :-)

This is interesting: do you have any reference?

I've tested with the difference between clobbering argv and call 
prctl: two demo programs are in the tools directory of the module 
project [2].

For what I observed, clobbering argv changes what shown in 
``/proc/PID/cmdline``, whereas prctl changes what can be read in 
``/proc/PID/status`` (and ``stat`` too). ``ps`` uses the former, but 
switches to the latter when calling ``ps a`` and ``ps f``. ``top`` 
toggles between the two pressing ``c``.

I don't know which method is better (well, I happen to prefer the 
extended visualization provided by the cmdline, which natively shows 
more detail than just the process name shown in ``status`` but this is 
probably subjective).

> Could this module be altered to use a prctl call in Linux (>2.6.9)?

I think is probably better to have both strings updated: I'd prefer 
this behavior instead of the title being set in different places on 
different Linux versions.

[2] http://code.google.com/p/py-setproctitle/source/browse/tools/

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5672>
_______________________________________


More information about the Python-bugs-list mailing list