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.
You can set the process name in the multiprocessing. Process class constructor or via the “name” property of the multiprocessing. Process class.
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
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.
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