shell top cmd监测进程CPU Memory使用情况
工作需要,记录一个top cmd 的用法记录Memory CPU使用状况,希望对你也有帮助。
1.遍历CPU或者Mem占用前5行的进程
top -o cpu -O +Rsize -l 5 -ncols 10 -n 5
其中-l 5,为查询5次,设0的话就是一直打印进程log。
-ncols 等于打印列数
-n 等于行数
-o 为指定key作为输出
如果想让它一直打印并保存输出,新增定位输出就好
top -o mem -O +Rsize -l 0 -ncols 20 -n 10 >> ~/Desktop/Memory.log
其中,也可以指定pid 来检索你要的进程 top信息.
top -pid 83499 -o mem -O +Rsize -l 0 -ncols 20
Processes: 491 total, 3 running, 488 sleeping, 2304 threads
2020/10/10 11:35:41
Load Avg: 2.83, 2.21, 1.88
CPU usage: 5.43% user, 8.27% sys, 86.28% idle
SharedLibs: 334M resident, 118M data, 98M linkedit.
MemRegions: 141121 total, 3622M resident, 147M private, 2358M shared.
PhysMem: 16G used (3481M wired), 337M unused.
VM: 2831G vsize, 1991M framework vsize, 135321(0) swapins, 235612(0) swapouts.
Networks: packets: 1754264/832M in, 1115933/272M out.
Disks: 4847211/55G read, 4361315/245G written.
PID COMMAND %CPU TIME #TH #WQ #PORTS MEM PURG CMPRS PGRP PPID STATE BOOSTS %CPU_ME %CPU_OTHRS UID FAULTS COW MSGSENT
83499 Terminal 0.0 00:05.00 14 7 389 188M 948K 0B 83499 1 sleeping *0[25] 0.00000 0.00000 501 156364 596 27642
Knowledge, like candlelight, can illuminate a person and countless people.