Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Linux uses commands to view process status information

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "Linux how to use commands to view process status information", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux how to use commands to view process status information" bar!

1. Preface

This article focuses on how to use the Linux command to view process status and information.

The process identifier process identifier (PID) is the digital number used by the Linux / Unix kernel (including the Windows operating system) to identify the process. Typically, a new process is created using the fork system call system call. You can monitor each PID (often called a task) under Linux. In this tutorial, I'll explain how to use the pidstat command to monitor tasks currently managed by the Linux kernel.

2. Introduction to the command `pidstat`

The pidstat command, which can also be used to monitor the children of selected tasks, has the following functions:

View specified process status information

View disk status information, Apache/Nginx/Lighttpd / O information, and status information of their child processes for specified processes

View task statistics associated with threads

View the CPU statistics report for each active task.

View page errors and memory utilization for a specific process

Confirm a memory leak for a specific process.

Other more

3. Install `pidstat`

To use the pidstat command, you must first install the pidstat command

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

Loaded plug-in: fastestmirror

Loading mirror speeds from cached hostfile

Base: mirrors.aliyun.com

Epel: mirror01.idc.hinet.net

Extras: mirrors.aliyun.com

Updates: mirrors.aliyun.com

There is no package pidstat available.

Error: no processing required

Indicates that the bag was not found in the warehouse.

Use yum provides to find the package on which the pidstat command depends

[root@zcwyou ~] # yum provides pidstat

Loaded plug-in: 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

Source: base

Matching source:

File name: / usr/bin/pidstat

Find the package name corresponding to the pidstat command named sysstat

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

Running transaction

In the process of installing: lm_sensors-libs-3.4.0-6.20160601gitf9185e5.el7.x86_64 1 Universe 2

Installing: sysstat-10.1.5-17.el7.x86_64 2Univer 2

Validating: lm_sensors-libs-3.4.0-6.20160601gitf9185e5.el7.x86_64 1 Universe 2

Validating: sysstat-10.1.5-17.el7.x86_64 2 Universe 2

Installed:

Sysstat.x86_64 0RO 10.1.5-17.el7

Installed as a dependency:

Lm_sensors-libs.x86_64 0RO 3.4.0-6.20160601gitf9185e5.el7

Over!

Indicates that the installation has been successful

4. `pidstat` command syntax

Pidstat uses syntax

[root@zcwyou ~] # pidstat options interval count

That is,

Pidstat option interval number

Try the following command:

[root@zcwyou ~] # pidstat

The output is as follows:

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 09 July 2019 x 86 CPU 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 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 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 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 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

Use pidstat to view process status

5. Use `pidstat` to view the Icano status of any process

Syntax:

Kernel version 2.6.20 or above is supported.

Pidstat-d-p process number

Pidstat-d-p process number 2 10

Pidstat-d-p process number 1 50

Check the pid status of a process. 6963 is the process number.

[root@zcwyou] # pidstat-d-p 6963

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 09 July 2019 x 86 CPU 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

The output explains:

PID-the process identification number of the task being monitored. .

KB_rd/s-the number of bytes produced by the read task from disk per second, in KByte.

KB_wr/s-the task produces bytes written to disk per second, in KByte.

Kilobytes-number of kilobytes written to disk that have been cancelled. This can happen when a task truncates some irty pagecache. In this case, there will be some IO that have already considered another task.

Command-the command executed by the process.

6. Find out the process statistics of the first five page errors

The following command shows you a report of five page error statistics for child processes of all tasks in the system at two-second intervals:

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

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 09 July 2019 x 86 CPU 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

Find out the process statistics of the first five page errors

The output explains:

PID-process number.

Minflt-nr-the total number of secondary failures generated by the task and its subtasks and collected during this interval.

Majflt-nr-the total number of major failures of the task and all its children, collected during this interval.

7. View CPU utilization

Execute the following command:

[root@zcwyou] # pidstat-T CHILD-u 22

Linux 3.10.0-957.12.2.el7.x86_64 (CentOS7.linuxrumen.com) 09 July 2019 x 86 CPU 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

Average time: UID PID usr-ms system-ms guest-ms Command

Average time: 0 500 50 kworker/1:1

Average time: 0 6931 500 tuned

Average time: 0 7583 5 150 pidstat

The output explains:

When you report global statistics for a task and all its children, the following values are displayed:

Usr-ms: the total number of milliseconds that the task and all its children spent executing at the user level (application), with or without priority, and collected during the interval. Note that this field does not include the time it takes to run the virtual processor.

System-ms: total milliseconds collected by the task and all its child nodes during this interval when executing at the system level (kernel)

Guest-ms: the total number of milliseconds that the task and all its child nodes spent in the virtual machine (running the virtual processor).

Thank you for reading, the above is the content of "Linux how to use commands to view process status information". After the study of this article, I believe you have a deeper understanding of how Linux uses commands to view process status information, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report