Open rudolfolah opened 4 months ago
Changing the entrypoint to bash
and trying the command worked:
docker run -it --rm --entrypoint bash python:3.12-bookworm
root@55008b874ebd:/# ps
PID TTY TIME CMD
1 pts/0 00:00:00 bash
7 pts/0 00:00:00 ps
root@55008b874ebd:/# ps -ewwo lstart,user:20,pid,ppid,time,%cpu,%mem,rss,sz,s,comm,cmd
STARTED USER PID PPID TIME %CPU %MEM RSS SZ S COMMAND CMD
Sat Jul 13 02:28:35 2024 root 1 0 00:00:00 0.0 0.0 3456 1118 S bash bash
Sat Jul 13 02:29:01 2024 root 8 1 00:00:00 0.0 0.0 3968 2146 R ps ps -ewwo lstart,user:20,pid,ppid,time,%cpu,%mem,rss,sz,s,comm,cmd
And here's what happens when we run it through Python:
docker run -it --rm python:3.12-bookworm
Python 3.12.4 (main, Jul 2 2024, 20:46:41) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run(args='-ewwo lstart,user:20,pid,ppid,time,%cpu,%mem,rss,sz,s,comm,cmd', executable='ps')
PID TTY TIME CMD
1 pts/0 00:00:00 python3
7 pts/0 00:00:00 ps
CompletedProcess(args='-ewwo lstart,user:20,pid,ppid,time,%cpu,%mem,rss,sz,s,comm,cmd', returncode=0)
>>> subprocess.run(args='-ewwo lstart,user:20,pid,ppid,time,%cpu,%mem,rss,sz,s,comm,cmd', executable='ps', shell=True)
error: improper AIX field descriptor
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
CompletedProcess(args='-ewwo lstart,user:20,pid,ppid,time,%cpu,%mem,rss,sz,s,comm,cmd', returncode=1)
The shell=True
may be causing the issue:
If shell is True, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want convenient access to other shell features such as shell pipes, filename wildcards, environment variable expansion, and expansion of ~ to a user’s home directory. However, note that Python itself offers implementations of many shell-like features (in particular, glob, fnmatch, os.walk(), os.path.expandvars(), os.path.expanduser(), and shutil).
Source code references for ps
:
Error when running on Debian 12. I found this error while working on #1
This thread may offer some insight into the issue: https://groups.google.com/g/linux.debian.user/c/fmOBn7aQo9Q?pli=1