Use system performance tools for Linux to display process statistics.
Install sysstat
package.
$ sudo apt install sysstat
Display CPU statistics once for specific process ID.
$ pidstat -u -p 5438
Linux 5.4.0-52-generic (swarm) 10/27/20 _x86_64_ (8 CPU) 21:24:39 UID PID %usr %system %guest %wait %CPU CPU Command 21:24:39 0 5438 1.22 1.44 0.00 0.00 2.66 4 cadvisor
Display CPU statistics five times using a second interval for specific process ID.
$ pidstat -u -p 5438 1 5
Linux 5.4.0-52-generic (swarm) 10/27/20 _x86_64_ (8 CPU) 21:29:46 UID PID %usr %system %guest %wait %CPU CPU Command 21:29:47 0 5438 0.00 1.00 0.00 0.00 1.00 4 cadvisor 21:29:48 0 5438 13.00 3.00 0.00 0.00 16.00 4 cadvisor 21:29:49 0 5438 1.00 0.00 0.00 0.00 1.00 4 cadvisor 21:29:50 0 5438 0.00 1.00 0.00 0.00 1.00 4 cadvisor 21:29:51 0 5438 1.00 1.00 0.00 0.00 2.00 4 cadvisor Average: 0 5438 3.00 1.20 0.00 0.00 4.20 - cadvisor
Display IO statistics once for specific command name.
$ pidstat -d -C postgres
Linux 5.4.0-52-generic (database) 10/27/20 _x86_64_ (8 CPU) 21:34:44 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:34:44 107 122 19.41 7.88 0.00 229 postgres 21:34:44 107 125 0.00 7.82 0.00 170 postgres 21:34:44 107 126 0.00 0.28 0.00 0 postgres 21:34:44 107 127 0.00 1.27 0.00 20 postgres 21:34:44 107 128 0.00 0.00 0.00 40 postgres 21:34:44 107 129 0.00 0.00 0.00 15 postgres 21:34:44 107 130 0.00 0.00 0.00 19 postgres 21:34:44 107 55003 0.00 0.00 0.00 0 postgres 21:34:44 107 55022 0.00 0.00 0.00 0 postgres 21:34:44 107 55079 0.00 0.00 0.00 0 postgres 21:34:44 107 55090 0.00 0.00 0.00 0 postgres
Display IO statistics two seconds interval for specific command name.
$ pidstat -d -C postgres 2
Linux 5.4.0-52-generic (database) 10/27/20 _x86_64_ (8 CPU) 21:36:18 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:20 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:22 107 127 0.00 4.00 0.00 0 postgres 21:36:22 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:24 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:26 107 122 334.79 20.00 0.00 0 postgres 21:36:26 107 55132 83.70 0.00 0.00 0 postgres 21:36:26 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:28 107 122 251.27 12.00 0.00 0 postgres 21:36:28 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:30 107 122 83.75 0.00 0.00 0 postgres 21:36:30 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:32 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:36:34 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command ^C Average: UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command Average: 107 122 74.38 3.55 0.00 0 postgres Average: 107 127 0.00 0.44 0.00 0 postgres
Display memory statistics once for specific process name.
$ pidstat -r -G "^php-fpm7.4$"
Linux 5.4.0-52-generic (news) 10/27/20 _x86_64_ (8 CPU) 21:48:21 UID PID minflt/s majflt/s VSZ RSS %MEM Command 21:48:21 0 121 0.01 0.00 230808 20164 0.06 php-fpm7.4 21:48:21 33 151 0.01 0.00 307596 26096 0.08 php-fpm7.4 21:48:21 33 152 0.01 0.00 307664 26036 0.08 php-fpm7.4 21:48:21 33 540 0.01 0.00 306956 24600 0.07 php-fpm7.4
Display CPU, IO and memory statistics once for specific process name.
$ pidstat -h -udr -G java
Linux 5.4.0-52-generic (drawio) 10/27/20 _x86_64_ (8 CPU) # Time UID PID %usr %system %guest %wait %CPU CPU minflt/s majflt/s VSZ RSS %MEM kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 21:50:34 998 109 0.07 0.06 0.00 0.00 0.13 5 0.28 0.01 12802732 456720 1.39 0.20 0.17 0.00 561 java
Display CPU statistics once for specific process name including threads.
$ pidstat -t -u -G java
Linux 5.4.0-52-generic (drawio) 10/27/20 _x86_64_ (8 CPU) 21:55:01 UID TGID TID %usr %system %guest %wait %CPU CPU Command 21:55:01 998 109 - 0.07 0.06 0.00 0.00 0.13 5 java 21:55:01 998 - 109 0.00 0.00 0.00 0.00 0.00 5 |__java 21:55:01 998 - 121 0.00 0.00 0.00 0.00 0.00 7 |__java 21:55:01 998 - 123 0.00 0.00 0.00 0.00 0.00 1 |__GC Thread#0 21:55:01 998 - 124 0.00 0.00 0.00 0.00 0.00 2 |__G1 Main Marker 21:55:01 998 - 126 0.00 0.00 0.00 0.00 0.00 3 |__G1 Refine#0 21:55:01 998 - 127 0.02 0.01 0.00 0.00 0.03 3 |__G1 Young RemSet 21:55:01 998 - 128 0.00 0.00 0.00 0.00 0.00 3 |__VM Thread 21:55:01 998 - 133 0.00 0.00 0.00 0.00 0.00 5 |__C2 CompilerThre 21:55:01 998 - 134 0.00 0.00 0.00 0.00 0.00 4 |__C1 CompilerThre 21:55:01 998 - 135 0.00 0.00 0.00 0.00 0.00 0 |__Sweeper thread 21:55:01 998 - 136 0.00 0.00 0.00 0.00 0.00 1 |__Common-Cleaner 21:55:01 998 - 138 0.03 0.04 0.00 0.00 0.06 2 |__VM Periodic Tas 21:55:01 998 - 139 0.00 0.00 0.00 0.00 0.00 0 |__AsyncFileHandle 21:55:01 998 - 140 0.00 0.00 0.00 0.00 0.00 0 |__FileHandlerLogF 21:55:01 998 - 144 0.00 0.00 0.00 0.00 0.00 3 |__GC Thread#1 21:55:01 998 - 145 0.00 0.00 0.00 0.00 0.00 4 |__GC Thread#2 21:55:01 998 - 146 0.00 0.00 0.00 0.00 0.00 5 |__GC Thread#3 21:55:01 998 - 147 0.00 0.00 0.00 0.00 0.00 2 |__GC Thread#4 21:55:01 998 - 148 0.00 0.00 0.00 0.00 0.00 0 |__GC Thread#5 21:55:01 998 - 149 0.00 0.00 0.00 0.00 0.00 6 |__GC Thread#6 21:55:01 998 - 150 0.00 0.00 0.00 0.00 0.00 7 |__GC Thread#7 21:55:01 998 - 151 0.00 0.00 0.00 0.00 0.00 5 |__http-nio-80-Blo 21:55:01 998 - 160 0.00 0.01 0.00 0.00 0.01 6 |__Catalina-utilit 21:55:01 998 - 161 0.00 0.01 0.00 0.00 0.01 7 |__Catalina-utilit 21:55:01 998 - 162 0.00 0.00 0.00 0.00 0.00 2 |__http-nio-80-exe 21:55:01 998 - 172 0.00 0.00 0.00 0.00 0.00 5 |__http-nio-80-Cli 21:55:01 998 - 173 0.00 0.00 0.00 0.00 0.00 7 |__http-nio-80-Acc
Display IO statistics using a second interval for executed command.
$ sudo pidstat --human -d 1 -e dd if=/dev/sda of=/dev/null bs=100M count=100 iflag=direct
Linux 5.4.0-52-generic (desktop) 10/27/20 _x86_64_ (4 CPU) 23:15:44 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 23:15:45 0 551349 479.1M 0.0B 0.0B 93 dd 23:15:46 0 551349 420.9M 0.0B 0.0B 97 dd 23:15:47 0 551349 200.0M 0.0B 0.0B 100 dd 23:15:48 0 551349 253.0M 0.0B 0.0B 99 dd 23:15:49 0 551349 347.0M 0.0B 0.0B 96 dd 23:15:50 0 551349 400.0M 0.0B 0.0B 98 dd 23:15:51 0 551349 400.0M 0.0B 0.0B 88 dd 23:15:52 0 551349 456.0M 0.0B 0.0B 110 dd 23:15:53 0 551349 344.0M 0.0B 0.0B 90 dd 23:15:54 0 551349 377.1M 0.0B 0.0B 106 dd 23:15:55 0 551349 370.9M 0.0B 0.0B 98 dd 23:15:56 0 551349 423.1M 0.0B 0.0B 98 dd 23:15:57 0 551349 360.9M 0.0B 0.0B 97 dd 23:15:58 0 551349 368.0M 0.0B 0.0B 83 dd 23:15:59 0 551349 465.2M 0.0B 0.0B 114 dd 23:16:00 0 551349 370.8M 0.0B 0.0B 97 dd 23:16:01 0 551349 416.0M 0.0B 0.0B 99 dd 23:16:02 0 551349 380.0M 0.0B 0.0B 97 dd 23:16:03 0 551349 368.0M 0.0B 0.0B 99 dd 23:16:04 0 551349 344.0M 0.0B 0.0B 98 dd 23:16:05 0 551349 356.0M 0.0B 0.0B 86 dd 23:16:06 0 551349 400.0M 0.0B 0.0B 101 dd 23:16:07 0 551349 500.0M 0.0B 0.0B 106 dd 23:16:08 0 551349 400.0M 0.0B 0.0B 93 dd 23:16:09 0 551349 482.7M 0.0B 0.0B 104 dd 100+0 records in 100+0 records out 10485760000 bytes (10 GB, 9.8 GiB) copied, 25.7672 s, 407 MB/s Average: 0 551349 387.3M 0.0B 0.0B 98 dd
Display CPU statistics once for itself.
$ pidstat -u -p SELF
Linux 5.4.0-52-generic (drawio) 10/27/20 _x86_64_ (8 CPU) 21:56:43 UID PID %usr %system %guest %wait %CPU CPU Command 21:56:43 0 3081 0.00 0.00 0.00 0.00 0.00 3 pidstat
Display CPU statistics once for all processes.
$ pidstat -u -p ALL
Linux 5.4.0-52-generic (drawio) 10/27/20 _x86_64_ (8 CPU) 21:56:48 UID PID %usr %system %guest %wait %CPU CPU Command 21:56:48 0 1 0.00 0.00 0.00 0.00 0.00 7 systemd 21:56:48 0 43 0.00 0.00 0.00 0.00 0.00 7 systemd-journal 21:56:48 0 78 0.00 0.00 0.00 0.00 0.00 5 systemd-udevd 21:56:48 100 84 0.00 0.00 0.00 0.00 0.00 6 systemd-network 21:56:48 0 87 0.00 0.00 0.00 0.00 0.00 5 cron 21:56:48 103 88 0.00 0.00 0.00 0.00 0.00 3 dbus-daemon 21:56:48 0 91 0.00 0.00 0.00 0.00 0.00 5 networkd-dispat 21:56:48 104 92 0.00 0.00 0.00 0.00 0.00 1 rsyslogd 21:56:48 0 93 0.00 0.00 0.00 0.00 0.00 6 systemd-logind 21:56:48 101 99 0.00 0.00 0.00 0.00 0.00 4 systemd-resolve 21:56:48 0 107 0.00 0.00 0.00 0.00 0.00 6 agetty 21:56:48 998 109 0.07 0.06 0.00 0.00 0.13 5 java 21:56:48 0 115 0.00 0.00 0.00 0.00 0.00 5 sshd 21:56:48 0 3053 0.00 0.00 0.00 0.00 0.00 1 bash 21:56:48 0 3083 0.00 0.00 0.00 0.00 0.00 7 pidstat