Linux使用Pidstat命令查看进程状态信息

系统 Linux
本文主要介绍如何使用Linux命令来查看进程状态和信息。

 1. 前言

本文主要介绍如何使用Linux命令来查看进程状态和信息。

[[275295]]

进程标识符process identifier (PID)是Linux / Unix内核(Windows操作系统也不例外)用来标识进程的数字号码。通常来说,使用fork system call系统调用创建新进程。可以在Linux下监视每个PID(通常也叫任务)。在本教程中,我将解释怎么使用pidstat命令监视当前由Linux内核管理的各个任务。

2. `pidstat`命令介绍

pidstat命令还可用于监视所选任务的子进程,该命令具有以下功能:

  1. 查看指定进程状态信息
  2. 查看指定进程的磁盘状态信息,Apache/Nginx/Lighttpd /O信息和他们子进程的状态信息
  3. 查看线程关联的任务统计信息
  4. 查看每个活动任务的CPU统计信息报告。
  5. 查看特定进程的页面错误和内存利用率
  6. 确认特定进程的内存泄漏。
  7. 其它更多

3. 安装`pidstat`

要使用使用pidstat命令,必须先安装pidstat命令

  1. [root@zcwyou ~]# yum -y install pidstat 

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com
  • epel: mirror01.idc.hinet.net
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
  • 没有可用软件包 pidstat。
  • 错误:无须任何处理

表明没有在仓库中找到这个包。

使用yum provides找到pidstat命令所依赖的包

  1. [root@zcwyou ~]# yum provides pidstat 

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com
  • epel: mirror01.idc.hinet.net
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
  • epel/x86_64/filelists_db | 11 MB 00:00:01
  • extras/7/x86_64/filelists_db | 246 kB 00:00:00
  • updates/7/x86_64/filelists_db | 4.6 MB 00:00:00
  • sysstat-10.1.5-17.el7.x86_64 : Collection of performance monitoring tools for Linux
  • 源 :base
  • 匹配来源:
  • 文件名 :/usr/bin/pidstat

找到pidstat命令所对应的包名为sysstat

  1. [root@zcwyou ~]# yum -y install sysstat 

Running transaction

正在安装 : lm_sensors-libs-3.4.0-6.20160601gitf9185e5.el7.x86_64 1/2

正在安装 : sysstat-10.1.5-17.el7.x86_64 2/2

验证中 : lm_sensors-libs-3.4.0-6.20160601gitf9185e5.el7.x86_64 1/2

验证中 : sysstat-10.1.5-17.el7.x86_64 2/2

已安装:

sysstat.x86_64 0:10.1.5-17.el7

作为依赖被安装:

lm_sensors-libs.x86_64 0:3.4.0-6.20160601gitf9185e5.el7

完毕!

表明已经安装成功

4. `pidstat`命令语法

pidstat使用语法

  1. [root@zcwyou ~]# pidstat options interval count 

pidstat 选项 间隔 数字

试试执行以下命令:

  1. [root@zcwyou ~]# pidstat 

输出结果如下:

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 2019年07月09日 x86_64(2 CPU)

08时13分30秒 UID PID %usr %system %guest %CPU CPU Command

08时13分30秒 0 1 0.04 0.68 0.00 0.72 1 systemd

08时13分30秒 0 2 0.00 0.00 0.00 0.00 1 kthreadd

08时13分30秒 0 3 0.00 0.04 0.00 0.04 0 ksoftirqd/0

08时13分30秒 0 7 0.00 0.01 0.00 0.01 0 migration/0

08时13分30秒 0 9 0.00 0.24 0.00 0.24 1 rcu_sched

08时13分30秒 0 13 0.00 0.00 0.00 0.00 1 migration/1

08时13分30秒 0 14 0.00 0.02 0.00 0.02 1 ksoftirqd/1

08时13分30秒 0 18 0.00 0.00 0.00 0.00 0 kdevtmpfs

08时13分30秒 0 30 0.00 0.01 0.00 0.01 0 kworker/0:1

08时13分30秒 0 37 0.00 0.00 0.00 0.00 1 khugepaged

08时13分30秒 0 47 0.00 0.06 0.00 0.06 1 kworker/u256:1

08时13分30秒 0 50 0.00 0.15 0.00 0.15 1 kworker/1:1

08时13分30秒 0 52 0.00 0.15 0.00 0.15 0 kworker/0:2

Linux使用pidstat命令查看进程状态信息

使用pidstat查看进程状态

5. 使用`pidstat`查看任意进程的I/O状态

语法:

内核版本2.6.20或以上版本才支持

pidstat -d -p 进程号

pidstat -d -p 进程号 2 10

pidstat -d -p 进程号 1 50

查看某进程的pid状态,6963为进程号

  1. [root@zcwyou ~]# pidstat -d -p 6963 

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 2019年07月09日x86_64 (2 CPU)

08时21分26秒 UID PID kB_rd/s kB_wr/s kB_ccwr/s Command

08时21分26秒 0 6963 1.91 0.00 0.00 sshd

输出结果解释:

PID – 正在监视的任务的进程标识号。.

kB_rd/s – 每秒从磁盘读取任务所产生的字节数,单位为KByte。

kB_wr/s – 任务产生每秒写入磁盘的字节数,单位为KByte。

kB_ccwr/s – 写入磁盘的任务已取消的千字节数。当任务截断某些irty pagecache时,可能会发生这种情况。在这种情况下,将会发生一些已经考虑了另一个任务的IO。

Command – 进程执行的命令.

6. 找出前5个页面错误的进程统计信息

以下命令将以两秒的间隔向您显示系统中所有任务的子进程的五个页面错误统计报告:

  1. [root@zcwyou ~]# pidstat -T CHILD -r 2 5 

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 2019年07月09日x86_64 (2 CPU)

08时26分48秒 UID PID minflt-nr majflt-nr Command

08时26分50秒 0 7575 228 0 pidstat

08时26分50秒 UID PID minflt-nr majflt-nr Command

08时26分52秒 0 7575 233 0 pidstat

找出前5个页面错误的进程统计信息

输出结果解释:

PID – 进程号.

minflt-nr – 任务及其子任务所产生的次要故障总数,并在该时间间隔内收集.

majflt-nr – 任务及其所有子项发生的主要故障总数,并在该时间间隔内收集.

7. 查看CPU利用率

执行以下命令:

  1. [root@zcwyou ~]# pidstat -T CHILD -u 2 2 

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 2019年07月09日 x86_64(2 CPU)

08时30分28秒 UID PID usr-ms system-ms guest-ms Command

08时30分30秒 0 6931 10 0 0 tuned

08时30分30秒 0 7583 0 20 0 pidstat

08时30分30秒 UID PID usr-ms system-ms guest-ms Command

08时30分32秒 0 50 0 10 0 kworker/1:1

08时30分32秒 0 7583 10 10 0 pidstat

平均时间: UID PID usr-ms system-ms guest-ms Command

平均时间: 0 50 0 5 0 kworker/1:1

平均时间: 0 6931 5 0 0 tuned

平均时间: 0 7583 5 15 0 pidstat

输出结果解释:

报告任务及其所有子项的全局统计信息时,将显示以下值:

usr-ms:任务及其所有子项在用户级别(应用程序)执行时所花费的总毫秒数,具有或不具有优先级,并在时间间隔内收集。请注意,此字段不包括运行虚拟处理器所花费的时间。

system-ms:在系统级别(内核)执行时,任务及其所有子节点在此时间间隔内收集的总毫秒数

guest-ms:任务及其所有子节点在虚拟机(运行虚拟处理器)中花费的总毫秒数。

责任编辑:华轩 来源: 今日头条
相关推荐

2021-09-10 10:35:25

Linuxstat命令文件系统

2009-10-27 16:34:02

linux top命令

2009-10-15 09:58:13

Linux系统信息查看

2009-10-27 16:01:58

linux w命令

2010-06-13 15:13:45

Linux 查看进程

2009-10-27 15:58:06

linux进程查看

2010-03-02 14:01:58

Linux硬件信息命令

2011-07-19 09:25:52

2010-06-11 16:57:37

Linux 查看进程

2009-10-27 16:14:11

linux进程查看

2010-05-27 14:42:40

Linux查看端口

2010-06-07 12:51:51

Linux 查看进程

2013-11-06 15:01:51

Linux命令内存

2009-12-25 10:48:23

ps -aux

2010-06-04 14:41:38

Linux 查看进程

2021-04-16 08:05:52

命令SELinuxSestatus

2010-05-27 14:29:53

Linux查看进程

2010-05-27 17:17:29

Linux查看环境变量

2016-01-04 15:17:50

Linux命令行硬件

2020-11-11 10:25:51

Linuxss命令
点赞
收藏

51CTO技术栈公众号