According to the documentation of Popen, it seems possible, in POSIX systems, to set the name of the process as it is returned by 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.
On my Ubuntu 22.04 machine, if I run the following python script:
import subprocesswith subprocess.Popen(["foo", "10"], executable="sleep", shell=False) as process: passand then run ps -ae in another terminal, the last lines of output are
22854 ? 00:00:00 python3.10 22857 ? 00:00:00 sleep 22860 pts/0 00:00:00 psI would expect to see foo instead of sleep. Could you please explain me what I am getting wrong?