Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Thanks in advance

like image 980
Emilio Avatar asked Feb 19 '09 10:02

Emilio


People also ask

How do you change a process name in python?

You can set the process name in the multiprocessing. Process class constructor or via the “name” property of the multiprocessing. Process class.

How do you define a process in python?

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.

How do you create a new process in python?

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.


1 Answers

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.

like image 95
piro Avatar answered Sep 20 '22 09:09

piro