Marcelo Fernández <marcelo.fidel.fernan...@gmail.com> added the comment:

2009/12/6 Daniele Varrazzo <rep...@bugs.python.org>:
>> 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?

For example, take a look at the comments here:
http://abock.org/2006/02/09/changing-process-name-in-mono

It seems that some utilities and programs (killall,
gnome-system-monitor, and so on) looks for the process name in
/proc/PID/status, not in /proc/PID/cmdline, so it should be better (in
Linux), to modify both, /proc/PID/cmdline (changing argv) *and*
/proc/PID/status (calling prctl()).

I installed py-setproctitle, and can't kill it with killall once I set
the name to "hello", for example. :-(

[1]+  Detenido                python
marc...@marcelo-laptop:~/src/py-setproctitle$ ps a
  PID TTY      STAT   TIME COMMAND
 1030 tty4     Ss+    0:00 /sbin/getty -8 38400 tty4
 1033 tty5     Ss+    0:00 /sbin/getty -8 38400 tty5
 1049 tty2     Ss+    0:00 /sbin/getty -8 38400 tty2
 1050 tty3     Ss+    0:00 /sbin/getty -8 38400 tty3
 1052 tty6     Ss+    0:00 /sbin/getty -8 38400 tty6
 1349 tty7     Ss+   17:14 /usr/bin/X :0 -br -verbose -auth
/var/run/gdm/auth-for-gdm-XhETSO/database -nolisten tcp vt7
 2225 tty1     Ss+    0:00 /sbin/getty -8 38400 tty1
10344 pts/0    Ss+    0:00 /bin/bash -l
11923 pts/1    Ss     0:00 bash
12068 pts/2    Ss+    0:00 bash
12485 pts/1    T      0:00 hello
12496 pts/1    R+     0:00 ps a
marc...@marcelo-laptop:~/src/py-setproctitle$ killall hello
hello: proceso no encontrado

Another example: The gnome-system-monitor still lists the 'hello'
process (PID 12485) like 'python'. So we should try

> 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``.

Sorry, but here (Ubuntu 9.10) it works the other way around: "ps"
lists the /proc/PID/status -> name field and "ps a" lists the
/proc/PID/cmdline. But I got the explanation. :-)

> 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.

IMHO, I'd prefer both things: to change the argv array *and* calling
prctl() if possible (Linux >2.6.9). If Linux is lower than 2.6.9,
fallback to change argv only.

Regards
-- 
Marcelo F. Fernández
Buenos Aires, Argentina
Licenciado en Sistemas - CCNA

E-Mail: marcelo.fidel.fernan...@gmail.com
Blog: http://blog.marcelofernandez.info
Twitter: http://twitter.com/fidelfernandez

----------

_______________________________________
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