[LINUX] ps command cheat sheet

It's for personal use so don't hit it

■ Command

Detailed display of all processes


ps -alx
ps -alxf     #Hierarchical display

Detailed display of a specific process


ps -alx | grep <processname>
ps -alx | head -n 1 && ps -alx | grep <processname>     #Add header line

Shows CPU usage and memory usage of all processes


ps -aux
ps -aux --sort -%cpu | head -n 10      #Top 10 CPU usage from all processes
ps -aux --sort -%mem | head -n 10      #Top 10 MEM usages from all processes

Show start time of all processes, time since start, CPU time, user


ps ax -o lstart,etime,time,user,command

Show process for a specific user


ps l -u <username>

■ Explanation

Status display of all processes

Status display of all processes


ps -alx
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0   580     1  20   0  35136  2468 ep_pol Ss   ?          0:00 /usr/lib/systemd/systemd-journald
5   998   802     1  20   0 117804  1644 poll_s S    ?          0:00 /usr/sbin/chronyd
4     0  1398  1081  20   0 158924  5764 poll_s Ss   ?          0:00 sshd: root@pts/0
F process flag
         1:Not exec
         4:Superuser privileges
         5: 1+4
UID,PID,PPID user ID,Process ID,親Process ID
PRI,NI priority,Nice value
VSZ,RSS virtual memory size(KB),Memory size used(KB):Actual memory usage
The name of the kernel function that the WCHAN process is sleeping on, while it is running-Display with
STAT process status
          D:Non-interruptible sleep state(Normally during IO)
          R:Running or ready to run(In the run queue)
          S:Interruptable sleep state(Waiting for the event to complete)
          T:State stopped due to job control signal or traced
          W:Paging state
          X:Dead state(Should not be visible)
          Z:Zombie process
TTY control terminal
TIME CPU time (≠ startup time)
Command with COMMAND argument

Detailed display of a specific process

Detailed display of a specific process


ps -alx | grep zabbix
1   997  1161     1  20   0  78808  1256 do_wai S    ?          0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
1   997  1162  1161  20   0  78808  1308 hrtime S    ?          0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
1   997  1163  1161  20   0  78808  1820 poll_s S    ?          0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
1   997  1164  1161  20   0  78808  1820 poll_s S    ?          0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
1   997  1165  1161  20   0  78808  1820 poll_s S    ?          0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
1   997  1166  1161  20   0  78808  2224 hrtime S    ?          0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
1   997  1359     1  20   0 186612  3096 hrtime S    ?          0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
0     0  1421  1403  20   0 112728   972 -      R+   pts/0      0:00 grep --color=auto zabbix

Detailed display of a specific process(Add header line)


ps -alx | head -n 1  && ps -alx | grep zabbix
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
1   997  1161     1  20   0  78808  1256 do_wai S    ?          0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
1   997  1162  1161  20   0  78808  1328 hrtime S    ?          0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
1   997  1163  1161  20   0  78808  1820 poll_s S    ?          0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
1   997  1164  1161  20   0  78808  1820 poll_s S    ?          0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
1   997  1165  1161  20   0  78808  1820 poll_s S    ?          0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
1   997  1166  1161  20   0  78808  2224 hrtime S    ?          0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
1   997  1359     1  20   0 186612  3096 hrtime S    ?          0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
0     0  1451  1403  20   0 112728   968 -      R+   pts/0      0:00 grep --color=auto zabbix

Shows CPU usage and memory usage of all processes

Shows CPU usage and memory usage of all processes


ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       580  0.0  0.5  35136  2536 ?        Ss   20:30   0:00 /usr/lib/systemd/systemd-journald
named     1108  0.0 11.8 170104 58944 ?        Ssl  20:30   0:00 /usr/sbin/named -u named -c /etc/named.conf
chrony     802  0.0  0.3 117804  1644 ?        S    20:30   0:00 /usr/sbin/chronyd
USER execution user name
PID process ID
%CPU process cpu utilization, percentage of time spent running during process lifetime
%Percentage of process resident set size to physical memory of MEM machine.
VSZ,RSS virtual memory size(KB),Memory size used(KB):Actual memory usage
TTY control terminal
STAT process status
          D:Non-interruptible sleep state(Normally during IO)
          R:Running or ready to run(In the run queue)
          S:Interruptable sleep state(Waiting for the event to complete)
          T:State stopped due to job control signal or traced
          W:Paging state
          X:Dead state(Should not be visible)
          Z:Zombie process
Start time or start date of the START process
TIME CPU time (≠ startup time)
Command with COMMAND argument

Show start time of all processes, time since start, CPU time, user

Show start time of all processes, time since start, CPU time, user


ps ax -o lstart,etime,time,user,command
                 STARTED     ELAPSED     TIME USER     COMMAND
Sat Nov 21 20:30:18 2020    01:06:53 00:00:02 root     /usr/lib/systemd/systemd --switched-root --system --deserialize 22
Sat Nov 21 20:30:31 2020    01:06:40 00:00:00 root     /usr/libexec/postfix/master -w
Sat Nov 21 20:30:31 2020    01:06:40 00:00:00 postfix  qmgr -l -t unix -u
Sat Nov 21 20:36:19 2020    01:00:52 00:00:00 root     -bash
Sat Nov 21 21:01:01 2020       36:10 00:00:00 root     /usr/sbin/anacron -s
Sat Nov 21 21:37:11 2020       00:00 00:00:00 root     ps ax -o lstart,etime,time,user,command

Show process for a specific user

Show process for a specific user


ps l -u postfix
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4    89  1335  1328  20   0  89804  4052 ep_pol S    ?          0:00 pickup -l -t unix -u
4    89  1336  1328  20   0  89872  4080 ep_pol S    ?          0:00 qmgr -l -t unix -u

Show process for a specific user(Error for non-existent users)


ps l -u testuser999
error: user name does not exist

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).

■ Reference

ps http://linuxjm.osdn.jp/html/procps/man1/ps.1.html

UNIX command dictionary ps https://codezine.jp/unixdic/w/ps

ps command summary https://qiita.com/s_suzaku/items/9967fabc1dd8b9856f1a

How to use Linux command "ps" and options (check process list) https://26gram.com/linux-ps-command

ps --Command (program) description --Linux command list https://kazmax.zpp.jp/cmd/p/ps.1.html

Recommended Posts

ps command cheat sheet
conda command cheat sheet
Linux command cheat sheet
Curry cheat sheet
ps command "wchan"
SQLite3 cheat sheet
pyenv cheat sheet
PIL / Pillow cheat sheet
Spark API cheat sheet
Python3 cheat sheet (basic)
PySpark Cheat Sheet [Python]
Python sort cheat sheet
Go language cheat sheet
tox configuration file cheat sheet
Frequently used ps command options
[Python3] Standard input [Cheat sheet]
Data Science Cheat Sheet (Python)
Slack API attachments cheat sheet
Python Django Tutorial Cheat Sheet
scikit learn algorithm cheat sheet
Apache Beam Cheat Sheet [Python]
Google Test / Mock personal cheat sheet
Continuation Passing Style (CPS) Cheat Sheet
Python cheat sheet (for C ++ experienced)
Process confirmation command ps option memorandum
Python Computation Library Cheat Sheet ~ itertools ~
Curry cheat sheet [Description example list version]
AtCoder cheat sheet in python (for myself)
Blender Python Mesh Data Access Cheat Sheet
Mathematical Optimization Modeler (PuLP) Cheat Sheet (Python)
A brief description of pandas (Cheat Sheet)