You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:44:31