Python – How to you change the process name of Wing IDE from python to something more descriptive

processpythonsystem-calls

In my process list under Ubuntu (using top/System Monitor) one of the largest memory hogs (200+Mb) was python. I searched a bit for one of my programs to be the cause until I realised this was my Python IDE (Wing), which itself is written in Python.

I thought I could change the name of the program by inserting setproctitle from the setproctitle package, but the python version that Wing is using is different from my own. setproctitle needs to be compiled and the python that wing uses is not a full installation (I asked Wing Support but they are unlikely to change that/incorporate setproctitle).

setproctitle can only change the name of the running process, so I could not make a script that starts Wing and then change the process name either.

After that I tried to write to /proc/PIDNUM/comm, but although that 'file' is 'rw', I am not allowed to write there.

I finally found a, not-so-portable, solution for this particular case. But I would like to know if there is a standard way of changing the process name of another (possible a child-) process with a Linux system call.

Best Answer

A process can only write to its own /proc/pid/comm. So since it sounds like you can modify the IDE's code, you can just have it write to /proc/self/comm.

Another option would be to change the name of its Python executable, and then change all the #! lines, but that may be a PITA.

Other—more painful—options would be writing some C code and using LD_PRELOAD or ptrace.

Related Question