我有一些 python 脚本名称 abc.py,但是当我执行它时,我想使用一些不同的名称运行,比如“def”。
在 python 中是否可以不安装任何附加模块(procname)?
最佳答案
您可以使用纯 ctypes
来电:
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)
比较:
关于python - 执行 python 脚本时更改进程名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31132342/