Version: RHEL 7.9
I ran ps
command with -o
option like below. But, it just listed 2 processes :
The bash process with PID 4009
The ps command itself with PID 119893. Output also reveals that ps command's parent process is bash process with PID 4009
Why only bash and ps command listed in this output ? But a regular "ps -ef
" lists 663 processes.
johndoe@myserver:~ $ ps -o pid,ppid,args
PID PPID COMMAND
4009 4008 -bash
119893 4009 ps -o pid,ppid,args
johndoe@myserver:~ $
johndoe@myserver:~ $
johndoe@myserver:~ $
johndoe@myserver:~ $ ps -ef | wc -l
663
johndoe@myserver:~ $ ps -ef | head -10
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Mar26 ? 06:08:23 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0 0 Mar26 ? 00:00:26 [kthreadd]
root 6 2 0 Mar26 ? 00:15:37 [ksoftirqd/0]
root 7 2 0 Mar26 ? 00:02:32 [migration/0]
root 8 2 0 Mar26 ? 00:00:00 [rcu_bh]
root 9 2 0 Mar26 ? 00:47:13 [rcu_sched]
root 10 2 0 Mar26 ? 00:00:00 [lru-add-drain]
root 11 2 0 Mar26 ? 00:00:36 [watchdog/0]
root 12 2 0 Mar26 ? 00:00:30 [watchdog/1]
johndoe@myserver:~ $
johndoe@myserver:~ $ uname -a
Linux myserver.domain.net 3.10.0-1160.76.1.el7.x86_64 #1 SMP Tue Jul 26 14:15:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
johndoe@myserver:~ $
Same behaviour in Fedora 38 which has much newer kernel.
Following is what the manpage of Linux's ps
command says about -o
option. It does not seem to mention that the output will be restricted only for few processes.
-o format
User-defined format. format is a single argument in the form of a blank-separated or comma-separated list, which offers a way to specify individual output columns.
The recognized keywords are described in the STANDARD FORMAT SPECIFIERS section below. Headers may be renamed (ps -o pid,ruser=RealUser -o comm=Command) as desired.
If all column headers are empty (ps -o pid= -o comm=) then the header line will not be output. Column width will increase as needed for wide headers; this may be
used to widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm). Explicit width control (ps opid,wchan:42,cmd) is offered too. The behavior of ps
-o pid=X,comm=Y varies with personality; output may be one column named "X,comm=Y" or two columns named "X" and "Y". Use multiple -o options when in doubt. Use the
PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are macros that may be used to choose the default UNIX or BSD columns.