changing the process name of a python script
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.
Is there a way to change effective process name in Python?
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.
Change process name of Python script
There's no nice way that I've found to change the name of a running process in Windows, but you can create small .exe stubs with ExeMaker rather than resorting to py2exe packaging or copying the interpreter
The exe stub uses its own module name to calculate the .py script invoked. You should be able to use an exe resource editor to change the icon.
Change process name while executing a python script
You can use pure ctypes
calls:
import ctypes
lib = ctypes.cdll.LoadLibrary(None)
prctl = lib.prctl
prctl.restype = ctypes.c_int
prctl.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_ulong,
ctypes.c_ulong, ctypes.c_ulong]
def set_proctitle(new_title):
result = prctl(15, new_title, 0, 0, 0)
if result != 0:
raise OSError("prctl result: %d" % result)
Compare:
- http://man7.org/linux/man-pages/man2/prctl.2.html
- http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/prctl.h#L53
Related Topics
How to Get the Full Path of the Current File'S Directory
How to Check the Operating System in Python
Allowing Ctrl-C to Interrupt a Python C-Extension
Linux/Python: Encoding a Unicode String for Print
Using && in Subprocess.Popen for Command Chaining
Differencebetween C.Utf-8 and En_Us.Utf-8 Locales
Importerror: Libtk8.6.So: Cannot Open Shared Object File: No Such File or Directory
Determine If Package Installed with Yum Python API
Convert a Gtk Python Script to C
How to Convert Seconds to Hours, Minutes and Seconds
Mismatch Between Sys.Executable and Sys.Version in Python
How Does One Set Specific Vim-Bindings in Ipython 5.0.0
What Does --Enable-Optimizations Do While Compiling Python
Python Valueerror: Embedded Null Byte When Reading Png File from Bash Pipe
How to Return a Value from a Shell Script in a Python Script