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.
Thanks in advance
You can set the process name in the multiprocessing. Process class constructor or via the “name” property of the multiprocessing. Process class.
Python multiprocessing Process classAt first, we need to write a function, that will be run by the process. Then, we need to instantiate a process object. If we create a process object, nothing will happen until we tell it to start processing via start() function. Then, the process will run and return its result.
Fork system call use for creates a new process, which is called child process, which runs concurrently with process (which process called system call fork) and this process is called parent process. After a new child process created, both processes will execute the next instruction following the fork() system call.
I've recently written a Python module to change the process title in a portable way: check https://github.com/dvarrazzo/py-setproctitle
It is a wrapper around the code used by PostgreSQL to perform the title change. It is currently tested against Linux and Mac OS X: Windows (with limited functionality) and BSD portings are on the way.
Edit: as of July 2010, the module works with BSD and with limited functionality on Windows, and has been ported to Python 3.x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With