美文网首页linux
监控使用CPU或内存前十名进程

监控使用CPU或内存前十名进程

作者: 亮仔_c1b5 | 来源:发表于2019-10-15 00:02 被阅读0次

监控使用CPU或内存前十名进程
监控目的
监控方法
监控实现
一、监控目的
掌握系统进程对系统资源的使用情况,掌握机器的动态。

二、监控方法
2.1)监控命令
ps

top

2.2)监控方法
通过对任务管理器中的进程对内存或CPU的使用情况进行整合、排序得出结论

三、监控实现

!/bin/bash

Description:

Author: Bai Shuming

Created Time: 2019/05/28 03:52

统计使用内存和CPU前十名进程

统计系统中前十名使用内存最多的进程

memory() {

1、收集任务管理器进程信息

temp_file=mktemp memory.XXX
top -b -n 1 > $temp_file

2、按进程统计内存使用大小

tail -n +8 temp_file | awk '{array[NF]+=$6}END{for (i in array) print array[i],i}' |sort -k 1 -n -r|head -10

rm -f $temp_file
}

统计系统中前十名使用CPU最多的进程

cpu() {

1、收集任务管理器进程信息

temp_file=mktemp memory.XXX
top -b -n 1 > $temp_file

2、按进程统计内存使用大小

tail -n +8 temp_file | awk '{array[NF]+=$9}END{for (i in array) print array[i],i}' |sort -k 1 -n -r|head -10

rm -f $temp_file
}

echo memory
memory
echo cpu
cpu

相关文章

网友评论

    本文标题:监控使用CPU或内存前十名进程

    本文链接:https://www.haomeiwen.com/subject/juqhmctx.html