本文介紹經過ps和top查看進程的cpu、內存等使用狀況。mysql
ps命令相關參數定義:sql
輸出格式:shell
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
$ 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
-p 指定進程ID
-o 自定義輸出格式;app
$ 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:詳細的啓動時間;
etime: 從進程啓動到如今消逝的時間;
time: 累計消耗的cpu時間;
tid或者lwp:線程ID;
nlwp: 當前進程中的線程數;
%cpu: 該進程使用的CPU百分比;含義參考ps輸出格式中的」C」字段; CPU定義:進程佔用CPU時間除以進程啓動以來執行的時間;這個值不可能達到100%。與top命令的CPU不同。
%mem: 當前進程的常駐內存(resident set size)佔機器物理內存的百分比;即top命令顯示的%MEM字段;
rss: 當前進程常駐內存大小(resident set size),單位kiloBytes;
vsize: 或者vsz,當前進程佔用的VM虛擬內存大小,單位kB;
注意自定義參數以前使用逗號分隔,沒有空格;curl
再來看一下top命令:ide
$ 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虛擬內存大小;
%CPU: 當前進程佔用的CPU百分比;
%MEM: 當前進程佔用的物理內存百分比;
TIME+: 累計佔用CPU時間,單位分鐘,82分5.45秒;url
查看整個進程線程
$ 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
查看各個線程code
$ 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
查看某個進程的線程進程
$ 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