从ps
手册页:
默认情况下,ps 选择与当前用户具有相同有效用户 ID (euid=EUID) 并与调用者关联的所有进程。
在我的 Ubuntu 系统上,ps
没有任何标志的输出如下,符合预期:
$ ps
PID TTY TIME CMD
6444 pts/11 00:00:00 bash
14605 pts/11 00:00:00 ps
现在再次从ps
OUTPUT MODIFIERS 的手册页:
e Show the environment after the command.
但是当我尝试时ps e
,我会列出更多进程:
$ ps e
PID TTY STAT TIME COMMAND
85 pts/1 Ss+ 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
100 pts/2 Ss+ 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
115 pts/3 Ss+ 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
130 pts/4 Ss+ 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
146 pts/5 Ss+ 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
174 pts/6 Ss+ 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
2988 pts/9 Ss 0:01 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
3477 pts/9 S+ 0:00 vi stepniak.json SHELL=/bin/bash WSL_DISTRO_NAME=Ubuntu-20.04 WT_SESSION=55c420c4-12cf-4f4c-b957-b0b42e2777b8 JAVA_HOME=/home/myr
4513 pts/0 Ss+ 0:02 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
4540 pts/7 Ss+ 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
5653 pts/10 Ss+ 0:01 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
6444 pts/11 Ss 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
7942 pts/12 Ss 0:00 -bash HOSTTYPE=x86_64 LANG=C.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
17962 pts/12 Sl 0:03 /home/myroot/jdk-11.0.2/bin/java -classpath /mnt/c/k8s-developer/maven-3.6.3/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf
17997 pts/11 R+ 0:00 ps e SHELL=/bin/bash WSL_DISTRO_NAME=Ubuntu-20.04 WT_SESSION=7e85f66b-c77a-42da-8782-c0912c196b46 JAVA_HOME=/home/myroot/jdk-11.0
24958 pts/12 Sl 1:05 java -jar myapp.jar SHELL=/bin/bash WSL_DISTRO_NAME=Ubuntu-20.04 WT_SESSION=d9a61855-27fe-4757-a7c9-a38f38fe7fc7 JAVA
25185 pts/12 S+ 0:03 tail -f nohup.out SHELL=/bin/bash WSL_DISTRO_NAME=Ubuntu-20.04 WT_SESSION=d9a61855-27fe-4757-a7c9-a38f38fe7fc7 JAVA_HOME=/home/my
据我了解,e
它是一个 OUTPUT 修饰符,它不应更改用于选择进程的标准(通常使用-e
、a
等来完成)。
那么为什么ps e
列出的进程多于ps
?
注意: ps -f
或ps -F
按预期工作 -
$ ps -F
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
myroot 6444 6443 0 4333 12404 2 00:25 pts/11 00:00:00 -bash
myroot 19976 6444 0 2655 3340 7 23:05 pts/11 00:00:00 ps -F
我的操作系统信息:
$ cat /etc/*rel*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal