关于subprocess.Popen无法设置可执行程序进程名称的问题咨询
subprocess.Popen无法设置可执行程序进程名称的问题咨询
我最近在研究subprocess.Popen设置进程名称的问题,根据Popen的文档说明,在POSIX系统里似乎可以设置ps命令返回的进程名称:
The executable argument specifies a replacement program to execute. It is very seldom needed. When
shell=False, executable replaces the program to execute specified by args. However, the original args is still passed to the program. Most programs treat the program specified by args as the command name, which can then be different from the program actually executed. On POSIX, the args name becomes the display name for the executable in utilities such as ps.
于是我在Ubuntu 22.04机器上运行了下面的Python脚本:
import subprocess with subprocess.Popen(["foo", "10"], executable="sleep", shell=False) as process: pass
接着我在另一个终端执行ps -ae,输出的最后几行是:
22854 ? 00:00:00 python3.10 22857 ? 00:00:00 sleep 22860 pts/0 00:00:00 ps
我本来预期会看到foo而不是sleep,有没有大佬能帮我解释下我哪里理解错了呀?
备注:内容来源于stack exchange,提问作者JtTest
相关产品推荐
相关产品推荐

