Ps

為什麼ps e顯示的程序比ps多?

  • December 28, 2021

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

現在再次從psOUTPUT 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 修飾符,它不應更改用於選擇程序的標準(通常使用-ea等來完成)。

那麼為什麼ps e列出的程序多於ps

注意: ps -fps -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

ps e使用 BSD 風格的選項(遵循procps命名法),並且這個

還將更改程序選擇以包括您擁有的其他終端 (TTY) 上的程序

e選項本身不會更改選擇,但會更改為預設選擇包括目前和其他終端上的所有程序的模式。

其他 BSD 風格的輸出控制選項具有相同的效果。參見例如ps lps u

引用自:https://unix.stackexchange.com/questions/684195