pythonprocessargumentshide

Is there a way to change effective process name in Python?


Can I change effective process name of a Python script? I want to show a different name instead of the real name of the process when I get the system process list. In C I can set

strcpy(argv[0],"othername");

But in Python

argv[0] = "othername"

doesn't seem to work. When i get process list (with ps ax in my linux box) the real name doesn't change. I prefer a portable solution (or else one solution for posix and another for windows environments), if it exists.


Solution

  • Simply put, there's no portable way. You'll have to test for the system and use the preferred method for that system.

    Further, I'm confused about what you mean by process names on Windows.

    Do you mean a service name? I presume so, because nothing else really makes any sense (at least to my non-Windows using brain).

    If so, you need to use Tim Golden's WMI interface and call the .Change method on the service... at least according to his tutorial.

    For Linux none of the methods I found worked except for this poorly packaged module that sets argv[0] for you.

    I don't even know if this will work on BSD variants (which does have a setproctitle system call). I'm pretty sure argv[0] won't work on Solaris.