View the process CPU, memory usage

This article describes the process by ps and top view of cpu, memory and other usage.

1.ps command

1.1 Overview

ps command parameters defined:

  • -e or -A, to select all of the processes;
  • -L display thread;
  • -o customize the output format;

Output formats:

C    cpu使用百分比,为”使用的CPU时间/进程启动到现在的时间”
STIME 启动时间,小于24小时,格式为”HH:MM”,否则为“mmm dd”为 month day
TIME 累计使用CPU时间(user+system)
LWP 线程ID;
NLWP 当前进程中的线程数;
$ ps -ef |grep  orange
UID   PID  PPID  C  STIME  TTY          TIME    CMD
root     18666     1  0 Sep13 ?    00:00:00 /usr/local/orange_service/orange /usr/local/orange_service/orange_log.conf
root     18667 18666 13 Sep13 ?    7-12:15:51 /usr/local/lorange_service/orange /usr/local/orange_service/orange_log.conf

1.2 View thread

$ ps -eLf | grep orange
UID  PID  PPID   LWP   C  NLWP STIME TTY TIME CMD
root     18666     1       18666       0    1   Sep13 ?     00:00:00     /usr/local /orange /usr/local/orange_log.conf
root     18667  18666      18667       0    6   Sep13 ?      00:00:01   /usr/local /orange /usr/local/orange_log.conf 
root     18667  18666      18668       0    6   Sep13 ?      00:00:00 /usr/local /orange /usr/local/orange_log.conf
root     18667  18666     18669       12    6   Sep13 ?      7-01:27:27 /usr/local /orange /usr/local/orange_log.conf
root     18667  18666     18671       0    6   Sep13 ?      00:00:02  /usr/local /orange /usr/local/orange_log.conf
root     18667  18666     18672       0    6    Sep13 ?      10:45:49 /usr/local /orange /usr/local/orange_log.conf
root     18667  18666     18673       0    6   Sep13 ?      00:02:30 /usr/local /orange /usr/local/orange_log.conf

1.3 Use custom parameters

-p specify the process ID
-o custom output formats;

$ ps -p 1813 –o pid,ppid,lstart,etime,args
  PID    PPID                  STARTED     ELAPSED    COMMAND
 1813     1     Mon Aug 29 15:01:33 2016 71-02:34:45 /usr//sbin/zabbix_agentd

lstart: detailed start-up time;
etime: Start from the process to the current elapsed time;
Time: the CPU time accumulated consumption;
tid or lwp: thread ID;
NLWP: the number of threads in the current process;
% the CPU: the process uses CPU percentage; meaning of the reference ps output format "C" field; CPU definition: process CPU time divided by the time since the process started executing; this value can not be 100%. With the top command of the CPU is not the same.
% mem: permanent memory (resident set size) of the current process as a percentage of the machine physical memory; i.e., top field% MEM command displays;
RSS: the current process resident memory size (resident set size), the unit kiloBytes;
VSIZE: or vsz, currently occupied by the process VM virtual memory size in kB;
use commas to separate Note before custom parameters, with no spaces;

2.top command

Then look at the top command:

$ top
Tasks: 248 total,   1 running, 247 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:  16079044k total,  2654840k used, 13424204k free,   207208k buffers
Swap:  8110076k total,        0k used,  8110076k free,  2021428k cached

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU  %MEM    TIME+  COMMAND                                                     
 1677 mysql     20   0 2298m  59m 7376 S   0.3   0.4    82:05.45    mysqld  

VIRT: VM virtual memory size used by the current process;
% CPU: CPU percentage occupied by the current process;
% MEM: percentage of the physical memory occupied by the current process;
the TIME +: cumulative CPU time, in minutes, 82 minutes 5.45 seconds;

2.1 View thread

View the entire process

$ top | grep orange
10151 root      20   0 1644m 112m 1268 S 77.5  0.7  69:35.22 orange                                                    
10151 root      20   0 1644m 114m 1268 S 49.2  0.7  69:36.70 orange                                                    
10151 root      20   0 1644m 115m 1268 S 69.8  0.7  69:38.80 orange                                                    
10151 root      20   0 1644m 123m 1268 S 63.5  0.8  69:40.71 orange                                                    

Check each thread

$ top -H | grep orange
10158 root      20   0 1644m 111m 1268 S 37.6  0.7  13:51.40 orange                                                    
10169 root      20   0 1644m 111m 1268 S 31.7  0.7   9:23.18 orange                                                    
10160 root      20   0 1644m 111m 1268 S 23.8  0.7   9:14.69 orange                                                    
10173 root      20   0 1644m 111m 1268 S  2.0  0.7   6:39.96 orange                                                    
10156 root      20   0 1644m 124m 1268 S 19.3  0.8  13:59.24 orange                                                    
10160 root      20   0 1644m 124m 1268 S 15.0  0.8   9:15.14 orange                                                    
10169 root      20   0 1644m 124m 1268 S 14.0  0.8   9:23.60 orange                                                    
10158 root      20   0 1644m 124m 1268 S 12.6  0.8  13:51.78 orange                                                    
10173 root      20   0 1644m 124m 1268 S  6.7  0.8   6:40.16 orange

View thread of a process

$ top –H –p 20675 
top - 21:49:06 up 79 days,  6:47,  7 users,  load average: 0.35, 0.39, 0.19
Tasks:  23 total,   0 running,  23 sleeping,   0 stopped,   0 zombie
Cpu(s):  5.5%us,  0.2%sy,  0.0%ni, 94.3%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  16079044k total, 15925868k used,   153176k free,   120784k buffers
Swap:  8110076k total,        0k used,  8110076k free, 15093952k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                     
20693 root      20   0 1580m  84m 1288 S  9.3  0.5   0:07.96 cl_promotionTra                                             
20692 root      20   0 1580m  84m 1288 S  7.0  0.5   0:09.03 cl_app_catalina                                             
20686 root      20   0 1580m  84m 1288 S  5.7  0.5   0:15.61 cl_cartAction.l                                             
20684 root      20   0 1580m  84m 1288 S  5.3  0.5   0:08.79 cl_shoppingActi                                             
20681 root      20   0 1580m  84m 1288 S  5.0  0.5   0:16.67 cl_cartAction1.                                             
20697 root      20   0 1580m  84m 1288 S  5.0  0.5   0:19.74 curl thread                                                 
20688 root      20   0 1580m  84m 1288 S  4.3  0.5   0:08.15 cl_app_catalina                                             
20694 root      20   0 1580m  84m 1288 S  2.7  0.5   0:08.88 cl_central1.log                                             
20698 root      20   0 1580m  84m 1288 S  0.3  0.5   0:00.01 timeDataFunc                                                
20675 root      20   0 1580m  84m 1288 S  0.0  0.5   0:00.00 orange                                                    
20677 root      20   0 1580m  84m 1288 S  0.0  0.5   0:00.00 FileCheck                                                   
20678 root      20   0 1580m  84m 1288 S  0.0  0.5   0:00.00 cl_promotionErr                                             
20679 root      20   0 1580m  84m 1288 S  0.0  0.5   0:05.73 cl_shoppingBigL                                             
20680 root      20   0 1580m  84m 1288 S  0.0  0.5   0:21.06 cl_pis-taskmgr2                                             
20682 root      20   0 1580m  84m 1288 S  0.0  0.5   0:19.70 cl_pis-taskmgr1                                             
20683 root      20   0 1580m  84m 1288 S  0.0  0.5   0:13.52 cl_checkoutMobi                                             
20685 root      20   0 1580m  84m 1288 S  0.0  0.5   0:05.04 cl_shoppingBigL                                             
20687 root      20   0 1580m  84m 1288 S  0.0  0.5   0:18.48 cl_checkoutLogg                                             
20689 root      20   0 1580m  84m 1288 S  0.0  0.5   0:07.90 cl_central.log                                              
20690 root      20   0 1580m  84m 1288 S  0.0  0.5   0:05.47 cl_shoppingBigL                                             
20691 root      20   0 1580m  84m 1288 S  0.0  0.5   0:18.05 cl_shoppingBigL                                             
20695 root      20   0 1580m  84m 1288 S  0.0  0.5   0:08.30 cl_pis-taskmgr.                                             
20696 root      20   0 1580m  84m 1288 S  0.0  0.5   0:00.25 cl_agent.log  

Guess you like

Origin www.cnblogs.com/lanyangsh/p/10990962.html