article/linux/linux分析进程内存占用.md
2024-01-14 22:55:02 +08:00

38 lines
914 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 寻找 内存orCPU 占用最高的程序
查看内存最多的进程
方法1
```
ps -aux | sort -k4nr | head -10
```
命令解释:
1. `ps`参数a指代all——所有的进程u指代userid——执行该进程的用户idx指代显示所有程序不以终端机来区分。ps -aux的输出格式如下
2. sort -k4nr中k代表从根据哪一个关键词排序后面的数字4表示按照第四列排序n指代numberic sort根据其数值排序r指代reverse这里是指反向比较结果输出时默认从小到大反向后从大到小。。本例中可以看到%MEM在第4个位置根据%MEM的数值进行由大到小的排序。-k3表示按照cpu占用率排序。
方法2
top 然后按下M注意大写
查看CPU 占用最多的进程
方法1
```
ps -aux | sort -k3nr | head -3
```
方法2
top 然后按下P注意大写)