Linux 进程之pidstat_linux pidstat

03:54:27 PM 0 356 0.00 0.00 0.00 0.00 0 sshd
03:54:27 PM 0 360 0.00 0.00 0.00 0.00 2 sshd
03:54:27 PM 0 482 0.00 0.00 0.00 0.00 3 sshd
03:54:27 PM 0 486 0.00 0.00 0.00 0.00 0 sshd
03:54:27 PM 0 5174 0.00 0.00 0.00 0.00 1 sshd


### 2.2 pidstat -d



-d Report I/O statistics



Linux 3.10.0-957.el7.x86_64 (localhost.localdomain) 11/24/2022 _x86_64_ (4 CPU)

04:02:11 PM UID PID kB_rd/s kB_wr/s kB_ccwr/s Command
04:02:11 PM 0 1 0.96 1.64 0.13 systemd
04:02:11 PM 0 365 0.00 0.00 0.00 bash
04:02:11 PM 0 490 0.00 0.00 0.00 bash
04:02:11 PM 0 2173 0.00 0.00 0.00 xfsaild/dm-0
04:02:11 PM 0 2254 0.00 0.00 0.00 systemd-journal
04:02:11 PM 0 2276 0.00 0.00 0.00 lvmetad
04:02:11 PM 0 2297 0.02 0.00 0.00 systemd-udevd
04:02:11 PM 0 4496 0.00 0.02 0.00 auditd
04:02:11 PM 0 4524 0.00 0.00 0.00 accounts-daemon
04:02:11 PM 172 4527 0.00 0.00 0.00 rtkit-daemon
04:02:11 PM 0 4528 0.00 0.00 0.00 alsactl
04:02:11 PM 998 4533 0.00 0.00 0.00 polkitd
04:02:11 PM 70 4539 0.00 0.00 0.00 avahi-daemon
04:02:11 PM 0 4540 0.00 0.00 0.00 bluetoothd
04:02:11 PM 81 4541 0.00 0.00 0.00 dbus-daemon
04:02:11 PM 0 4549 0.00 0.00 0.00 udisksd
04:02:11 PM 0 4551 0.00 0.00 0.00 abrtd
04:02:11 PM 0 4554 0.00 0.00 0.00 abrt-watch-log
04:02:11 PM 994 4561 0.00 0.00 0.00 lsmd
04:02:11 PM 0 4591 0.00 0.00 0.00 gssproxy
04:02:11 PM 0 4635 0.00 0.00 0.00 firewalld


UID:正在监视的任务的真实用户标识号。  
 PID:正在监视的任务的标识号。  
 kB\_rd/s:任务每秒从磁盘读取的 kilobytes。  
 kB\_wr/s:任务每秒已写入或将写入磁盘的 kilobytes。  
 kB\_ccwr/s:任务已经取消写入磁盘的 kilobytes,这可能发生在任务截断某些脏页缓存时(dirty pagecache:缓存中的数据还没有写入磁盘)。  
 Command:任务的命令名称。


### 2.3 pidstat -l



-l Display the process command name and all its arguments.


显示任务的完整路径和任务执行时的参数,和从/proc/fd/cmdline 中的值一样



04:25:21 PM UID PID %usr %system %guest %CPU CPU Command

04:25:21 PM 0 614 0.00 0.00 0.00 0.00 1 kworker/u8:0
04:25:21 PM 0 1463 0.00 0.00 0.00 0.00 2 i915/signal:0
04:25:21 PM 0 2173 0.00 0.01 0.00 0.01 3 xfsaild/dm-0
04:25:21 PM 0 2174 0.00 0.00 0.00 0.00 0 kworker/0:1H
04:25:21 PM 0 2254 0.00 0.00 0.00 0.00 1 /usr/lib/systemd/systemd-journald
04:25:21 PM 0 2276 0.00 0.00 0.00 0.00 2 /usr/sbin/lvmetad -f
04:25:21 PM 0 2295 0.00 0.00 0.00 0.00 3 kworker/3:1H
04:25:21 PM 0 2297 0.00 0.00 0.00 0.00 3 /usr/lib/systemd/systemd-udevd
04:25:21 PM 0 4428 0.00 0.00 0.00 0.00 1 xfsaild/sda2
04:25:21 PM 0 4496 0.00 0.00 0.00 0.00 2 /sbin/auditd
04:25:21 PM 0 4498 0.00 0.00 0.00 0.00 0 /sbin/audispd
04:25:21 PM 0 4499 0.00 0.00 0.00 0.00 2 /usr/sbin/sedispatch
04:25:21 PM 32 4522 0.00 0.00 0.00 0.00 3 /sbin/rpcbind -w
04:25:21 PM 0 4523 0.00 0.00 0.00 0.00 1 /usr/lib/systemd/systemd-logind
04:25:21 PM 0 4524 2.26 0.60 0.00 2.86 0 /usr/libexec/accounts-daemon
04:25:21 PM 172 4527 0.00 0.00 0.00 0.00 3 /usr/libexec/rtkit-daemon
04:25:21 PM 0 4528 0.00 0.00 0.00 0.00 0 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
04:25:21 PM 0 4529 0.00 0.00 0.00 0.00 0 /sbin/rngd -f


数据来源就是 /proc/fd/stat,/proc/fd/cmdline,/proc/fd/status:



[root@localhost ~]# strace -e trace=open pidstat -l

open(“/proc/1/stat”, O_RDONLY) = 4
open(“/proc/1/cmdline”, O_RDONLY) = 4
open(“/proc/1/status”, O_RDONLY) = 4
open(“/proc/2/stat”, O_RDONLY) = 4
open(“/proc/2/cmdline”, O_RDONLY) = 4
open(“/proc/2/status”, O_RDONLY) = 4
open(“/proc/3/stat”, O_RDONLY) = 4
open(“/proc/3/cmdline”, O_RDONLY) = 4
open(“/proc/3/status”, O_RDONLY) = 4
open(“/proc/5/stat”, O_RDONLY) = 4
open(“/proc/5/cmdline”, O_RDONLY) = 4
open(“/proc/5/status”, O_RDONLY) = 4
open(“/proc/7/stat”, O_RDONLY) = 4
open(“/proc/7/cmdline”, O_RDONLY) = 4
open(“/proc/7/status”, O_RDONLY) = 4
open(“/proc/8/stat”, O_RDONLY) = 4
open(“/proc/8/cmdline”, O_RDONLY) = 4
open(“/proc/8/status”, O_RDONLY) = 4


### 2.4 pidstat -p


查看指定进程的信息统计:



[root@localhost ~]# pidstat -p pidof top
Linux 3.10.0-957.el7.x86_64 (localhost.localdomain) 11/24/2022 _x86_64_ (4 CPU)

04:36:10 PM UID PID %usr %system %guest %CPU CPU Command
04:36:10 PM 0 4121 0.00 0.00 0.00 0.00 2 top


查看 pidstat 进程本身信息统计:



[root@localhost ~]# pidstat -p SELF
Linux 3.10.0-957.el7.x86_64 (localhost.localdomain) 11/24/2022 _x86_64_ (4 CPU)

04:36:41 PM UID PID %usr %system %guest %CPU CPU Command
04:36:41 PM 0 5340 0.00 0.00 0.00 0.00 3 pidstat


查看所有进程信息统计:



[root@localhost ~]# pidstat -p ALL
Linux 3.10.0-957.el7.x86_64 (localhost.localdomain) 11/24/2022 _x86_64_ (4 CPU)

04:37:28 PM UID PID %usr %system %guest %CPU CPU Command
04:37:28 PM 0 1 0.01 0.01 0.00 0.01 2 systemd
04:37:28 PM 0 2 0.00 0.00 0.00 0.00 0 kthreadd
04:37:28 PM 0 3 0.00 0.00 0.00 0.00 0 ksoftirqd/0
04:37:28 PM 0 5 0.00 0.00 0.00 0.00 0 kworker/0:0H
04:37:28 PM 0 7 0.00 0.00 0.00 0.00 0 migration/0
04:37:28 PM 0 8 0.00 0.00 0.00 0.00 0 rcu_bh
04:37:28 PM 0 9 0.00 0.07 0.00 0.07 1 rcu_sched
04:37:28 PM 0 10 0.00 0.00 0.00 0.00 0 lru-add-drain
04:37:28 PM 0 11 0.00 0.00 0.00 0.00 0 watchdog/0
04:37:28 PM 0 12 0.00 0.00 0.00 0.00 1 watchdog/1
04:37:28 PM 0 13 0.00 0.00 0.00 0.00 1 migration/1
04:37:28 PM 0 14 0.00 0.00 0.00 0.00 1 ksoftirqd/1


### 2.5 pidstat -r



-r Report page faults and memory utilization.



Linux 3.10.0-957.el7.x86_64 (localhost.localdomain) 11/24/2022 _x86_64_ (4 CPU)

04:41:20 PM UID PID minflt/s majflt/s VSZ RSS %MEM Command
04:41:20 PM 0 1 0.23 0.00 193952 7080 0.09 systemd
04:41:20 PM 0 356 0.00 0.00 165512 6560 0.08 sshd
04:41:20 PM 0 360 0.00 0.00 165208 5936 0.08 sshd
04:41:20 PM 0 365 0.00 0.00 116784 3432 0.04 bash
04:41:20 PM 0 411 0.00 0.00 72092 2872 0.04 sftp-server
04:41:20 PM 0 482 0.00 0.00 165512 6544 0.08 sshd
04:41:20 PM 0 486 0.00 0.00 165208 5936 0.08 sshd
04:41:20 PM 0 490 0.00 0.00 116916 3660 0.05 bash
04:41:20 PM 0 531 0.00 0.00 72092 2876 0.04 sftp-server
04:41:20 PM 0 2254 0.09 0.00 68504 28784 0.36 systemd-journal
04:41:20 PM 0 2276 0.00 0.00 201084 4180 0.05 lvmetad
04:41:20 PM 0 2297 0.00 0.00 48476 5880 0.07 systemd-udevd
04:41:20 PM 0 4496 0.00 0.00 62044 1292 0.02 auditd
04:41:20 PM 0 4498 0.00 0.00 84552 888 0.01 audispd
04:41:20 PM 0 4499 0.00 0.00 55632 1664 0.02 sedispatch
04:41:20 PM 32 4522 0.00 0.00 73648 1376 0.02 rpcbind
04:41:20 PM 0 4523 0.05 0.00 26460 1840 0.02 systemd-logind
04:41:20 PM 0 4524 0.00 0.00 396624 4604 0.06 accounts-daemon



minflt/s
Total number of minor faults the task has made per second, those which have not required loading a memory page from disk.

majflt/s
Total number of major faults the task has made per second, those which have required loading a memory page from disk.

VSZ
Virtual Size: The virtual memory usage of entire task in kilobytes.

RSS
Resident Set Size: The non-swapped physical memory used by the task in kilobytes.

%MEM
The tasks’s currently used share of available physical memory.


### 2.6 pidstat -s



-s Report stack utilization.


显示任务堆栈的使用情况:



Linux 3.10.0-957.el7.x86_64 (localhost.localdomain) 11/24/2022 _x86_64_ (4 CPU)

05:06:00 PM UID PID StkSize StkRef Command
05:06:00 PM 0 1 132 48 systemd
05:06:00 PM 0 356 132 40 sshd
05:06:00 PM 0 360 132 40 sshd
05:06:00 PM 0 365 132 28 bash
05:06:00 PM 0 411 132 32 sftp-server
05:06:00 PM 0 482 132 44 sshd
05:06:00 PM 0 486 132 40 sshd
05:06:00 PM 0 490 132 32 bash
05:06:00 PM 0 531 132 36 sftp-server
05:06:00 PM 0 2254 132 44 systemd-journal
05:06:00 PM 0 2276 132 24 lvmetad
05:06:00 PM 0 2297 132 48 systemd-udevd
05:06:00 PM 0 4496 132 44 auditd
05:06:00 PM 0 4498 132 12 audispd
05:06:00 PM 0 4499 132 20 sedispatch
05:06:00 PM 32 4522 132 20 rpcbind



StkSize
The amount of memory in kilobytes reserved for the task as stack, but not necessarily used.
(任务堆栈内存量的总大小,KB 为单位,但不一定使用全部)
StkRef
The amount of memory in kilobytes used as stack, referenced by the task.
(任务引用堆栈的内存量,KB 为单位(任务已经使用的堆栈内存大小))


### 2.7 pidstat -w



-w Report task switching activity



Linux 3.10.0-957.el7.x86_64 (localhost.localdomain) 11/24/2022 _x86_64_ (4 CPU)

05:06:29 PM UID PID cswch/s nvcswch/s Command
05:06:29 PM 0 1 0.49 0.01 systemd
05:06:29 PM 0 2 0.00 0.00 kthreadd
05:06:29 PM 0 3 0.27 0.00 ksoftirqd/0
05:06:29 PM 0 5 0.00 0.00 kworker/0:0H
05:06:29 PM 0 7 0.19 0.00 migration/0
05:06:29 PM 0 8 0.00 0.00 rcu_bh
05:06:29 PM 0 9 37.92 0.00 rcu_sched
05:06:29 PM 0 10 0.00 0.00 lru-add-drain
05:06:29 PM 0 11 0.25 0.00 watchdog/0
05:06:29 PM 0 12 0.25 0.00 watchdog/1
05:06:29 PM 0 13 0.18 0.00 migration/1
05:06:29 PM 0 14 0.06 0.00 ksoftirqd/1
05:06:29 PM 0 16 0.00 0.00 kworker/1:0H
05:06:29 PM 0 17 0.25 0.00 watchdog/2
05:06:29 PM 0 18 0.17 0.00 migration/2
05:06:29 PM 0 19 0.16 0.00 ksoftirqd/2
05:06:29 PM 0 21 0.00 0.00 kworker/2:0H
05:06:29 PM 0 22 0.25 0.00 watchdog/3
05:06:29 PM 0 23 0.18 0.00 migration/3



最后的话

最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!

资料预览

给大家整理的视频资料:

给大家整理的电子书资料:

如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
子书资料:

[外链图片转存中…(img-hA0paor0-1714136844555)]

如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 13
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值