Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the process name of a python script [duplicate]

Tags:

python

linux

Is there a way to change the name of a process running a python script on Linux?

When I do a ps, all I get are "python" process names.

like image 943
jldupont Avatar asked Feb 12 '10 22:02

jldupont


People also ask

How do you change the 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.


2 Answers

There is simplier (you don't need import any libs) but maybe not so elegant way. You have to do not use "env" inside the shebang line.

In other words, this will be named as "python" in process list:

#!/usr/bin/env python 

But this will be named with your scriptname:

#!/usr/bin/python 

So you'll be able to find it with something like pidof -x scriptname or ps -C scriptname

like image 154
Sasha Ru Avatar answered Nov 10 '22 06:11

Sasha Ru


http://code.google.com/p/procname/

Sample usage:

# Lets rename:     >>> procname.setprocname('My super name')      # Lets check. Press Ctrl+Z        user@comp:~/procname$ ps      PID TTY TIME CMD   13016 pts/2 00:00:00 bash  13128 pts/2 00:00:00 My super name <-- it's here 

It will only work on systems where prctl system call is present and supports PR_SET_NAME command.

like image 22
mechanical_meat Avatar answered Nov 10 '22 08:11

mechanical_meat