Use ipstat in linux to View resources used by processes

Source: Internet
Author: User
Many tools provide you with methods to view system resource usage from the device perspective. For example, you can use iostat to View disk io statistics.

Introduction

Many tools provide you with methods to view system resource usage from the device perspective. For example, use iostat to View disk io statistics:

linux:~ # iostat -d 3 Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtnsda 1.67 0.00 40.00 0 120

The above shows the statistical results from the sda perspective. Is there any way to view the usage of system resources by each process from the process perspective?

The pidstat tool can be used to obtain statistics of the cpu, memory, disk, and other system resources used by each process. pidstat is provided by the sysstat rpm package and can be used in suse11. Next, let's take a look at the specific usage of pidstat.

Default output

Run pidstat to output the cpu statistics of all active processes after the system is started:

linux:~ # pidstat Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 11:37:19 PID    %usr %system  %guest    %CPU   CPU  Command…… 11:37:19 11452 0.00 0.00 0.00 0.00 2 bash 11:37:19 11509 0.00 0.00 0.00 0.00 3 dd

The preceding output shows the kernel version, host name, date, and cpu architecture in the first line. The main columns are as follows:

  • 11: 37: 19: pidstat time point for obtaining information
  • PID: process pid
  • % Usr: cpu time ratio of processes in user mode
  • % System: cpu time ratio of processes in kernel mode
  • % CPU: Percentage of cpu time consumed by processes
  • CPU: indicates the core in which the process runs.
  • Command: pull the Command corresponding to the process

The default output of pidstat is the statistical information from the system startup to the execution time. Therefore, even if the cpu usage of a process is high, the output value may remain 0.

Specify the sampling period and number of samples

Like commands such as sar and iostat, you can also specify the sampling period and number of samples for the pidstat command. the command format is "pidstat [option] interval [count]". the following pidstat output takes 2 seconds as the sampling period and outputs two cpu usage statistics:

linux:~ # pidstat 2 2 Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 14:40:39 PID    %usr %system  %guest    %CPU   CPU  Command 14:40:41 9567 0.50 1.49 0.00 1.98 2 atop 14:40:41 12405 0.00 0.50 0.00 0.50 6 pidstat 14:40:41 PID    %usr %system  %guest    %CPU   CPU  Command 14:40:43 7830 0.50 0.50 0.00 1.00 7 runHpiAlarm 14:40:43 12405 0.00 1.00 0.00 1.00 6 pidstat

If count is not specified, pidstat will always output statistics.

Cpu usage statistics (-u)

With the-u option, pidstat displays the cpu usage statistics of each active process. executing "pidstat-u" is the same as executing "pidstat" separately.

Memory usage statistics (-r)

With the-r option, pidstat displays the memory usage statistics for each active process:

linux:~ # pidstat -r -p 13084 1 Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 15:08:18 PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command 15:08:19 13084 133835.00 0.00 15720284 15716896 96.26 mmmm 15:08:20 13084 35807.00 0.00 15863504 15849756 97.07 mmmm 15:08:21 13084 19273.87 0.00 15949040 15792944 96.72 mmmm

The output meanings of the above columns are as follows:

  • Minflt/s: Number of page missing errors per second (minor page faults). The number of page missing errors indicates the number of page fault times generated by ing the virtual memory address to the physical memory address.
  • Majflt/s: number of master page missing errors (major page faults) per second. when the virtual memory address is mapped to the physical memory address, the corresponding page is in swap, such page fault is major page fault, which is usually generated when the memory usage is insufficient.
  • VSZ: virtual memory used by the process (in kB)
  • RSS: physical memory used by the process (in kB)
  • % MEM: Percentage of memory used by the process
  • Command: pull the Command corresponding to the process

IO statistics (-d)

With the-d option, we can view the process IO statistics:

linux:~ # pidstat -d 1 2 Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 17:11:36 PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command 17:11:37 14579 124988.24 0.00 0.00 dd 17:11:37 PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command 17:11:38 14579 105441.58 0.00 0.00 dd
The main output is as follows:
  • KB_rd/s: the amount of data read by processes from the disk per second (in kB)
  • KB_wr/s: the amount of data written by the process to the disk per second (in kB)
  • Command: pull the Command corresponding to the process

Specific process statistics (-p)

With The-p option, we can view the system resource usage of a specific process:

linux:~ # pidstat -r -p 1 1 Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 18:26:17 PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command 18:26:18 1 0.00 0.00 10380 640 0.00 init 18:26:19 1 0.00 0.00 10380 640 0.00 init……
The above pidstat command takes 1 second as the sampling interval to view the memory usage of the init process.

Common pidstat commands

When pidstat is used for problem locating, the following commands are often used:

Pidstat-u 1

Pidstat-r 1

Pidstat-d 1

The preceding command takes one second as the information collection cycle to obtain the statistics of cpu, memory, and disk IO respectively.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.