CPU usage of Linux tracking process, memory consumption

Source: Internet
Author: User
Tags cpu usage

This article uses Java processes to illustrate

1. View the CPU usage of the Java process and its threads

First use PS-EF to find the Java process ID

# ps-ef|grep Java

Then use the top-p PID command to view the CPU used by the process, for example:

[[Email protected] ~]# top-p 23386
top-11:10:52 up 124 days, 19:18, 2 users, Load average:0.00, 0.00, 0.00
Tasks:1 Total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu (s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
mem:16294180k Total, 1601480k used, 14692700k free, 262604k buffers
swap:8191992k Total, 0k used, 8191992k free, 647004k cached

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
23386 Root 0 12.4g 299m 10m S 0.0 1.9 0:56.56 Java

At this point, if you want to see the CPU usage of the thread, manually enter Shift+h (show threads on) to switch the display thread.

We can use a parameter directly to open the thread-occupied CPU tracking by default, using the-h parameter, for example:

[[Email protected] ~]# top-p 23386-h
top-11:07:59 up 124 days, 19:15, 2 users, Load average:0.00, 0.00, 0.00
tasks:185 Total, 0 running, 185 sleeping, 0 stopped, 0 zombie
Cpu (s): 0.0%us, 0.0%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
mem:16294180k Total, 1601224k used, 14692956k free, 262596k buffers
swap:8191992k Total, 0k used, 8191992k free, 646996k cached

PID USER PR NI VIRT RES SHR S%cpu %MEMtime+COMMAND
23386 Root 0 12.4g 299m 10m S 0.3 1.9 0:00.02 Java
23387 Root 0 12.4g 299m 10m S 0.0 1.9 0:07.63 Java
23388 Root 0 12.4g 299m 10m S 0.0 1.9 0:00.08 Java
23389 Root 0 12.4g 299m 10m S 0.0 1.9 0:00.07 Java
23390 Root 0 12.4g 299m 10m S 0.0 1.9 0:00.08 Java
23391 Root 0 12.4g 299m 10m S 0.0 1.9 0:00.07 Java
23392 Root 0 12.4g 299m 10m S 0.0 1.9 0:00.08 Java
23393 Root 0 12.4g 299m 10m S 0.0 1.9 0:00.08 Java
23394 Root 0 12.4g 299m 10m S 0.0 1.9 0:00.08 Java

Note: Focus on%CPU to see which thread consumes the most CPU and then find the corresponding PID.

The time/time+ of the top command refers to the CPU time used by the process, not the time the process starts up to now, so if a process uses very little CPU, even if the process already exists for n long time, time/time+ is also a small number.

2. View Java Process Memory usage

# Cat/proc/23386/status
Name:java
State:s (sleeping)
Tgid:23386
Pid:23386
Ppid:1
tracerpid:0
uid:0 0 0 0
gid:0 0 0 0
utrace:0
fdsize:256
groups:0
vmpeak:13003444 KB
vmsize:13003444 KB
vmlck:0 KB
vmhwm:311496 KB
vmrss:307048 KB
vmdata:12846208 KB
vmstk:88 KB
Vmexe:32 KB
vmlib:14256 KB
vmpte:1704 KB
vmswap:0 KB
threads:194

Description

vmrss:307048 KB represents the physical memory that is occupied.

threads:194 says 194 threads are currently open altogether.


CPU usage of Linux tracking process, memory consumption

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.