use*_*525 224 linux memory ram opensuse
我有一台12G内存的服务器.顶部的片段如下所示:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12979 frank 20 0 206m 21m 12m S 11 0.2 26667:24 krfb
13 root 15 -5 0 0 0 S 1 0.0 36:25.04 ksoftirqd/3
59 root 15 -5 0 0 0 S 0 0.0 4:53.00 ata/2
2155 root 20 0 662m 37m 8364 S 0 0.3 338:10.25 Xorg
4560 frank 20 0 8672 1300 852 R 0 0.0 0:00.03 top
12981 frank 20 0 987m 27m 15m S 0 0.2 45:10.82 amarok
24908 frank 20 0 16648 708 548 S 0 0.0 2:08.84 wrapper
1 root 20 0 8072 608 572 S 0 0.0 0:47.36 init
2 root 15 -5 0 0 0 S 0 0.0 0:00.00 kthreadd
Run Code Online (Sandbox Code Playgroud)
该free -m显示以下内容:
total used free shared buffers cached
Mem: 12038 11676 362 0 599 9745
-/+ buffers/cache: 1331 10706
Swap: 2204 257 1946
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,系统只有362 MB的可用内存.我的问题是:如何找出消耗大部分内存的进程?
就像背景信息一样,系统正在运行64bit OpenSuse 12.
ris*_*dar 311
在linux/unix中使用top命令使用快速提示
$ top
Run Code Online (Sandbox Code Playgroud)
然后按Shift+ m(即写一个大写M).
从 man top
SORTING of task window
For compatibility, this top supports most of the former top sort keys.
Since this is primarily a service to former top users, these commands do
not appear on any help screen.
command sorted-field supported
A start time (non-display) No
M %MEM Yes
N PID Yes
P %CPU Yes
T TIME+ Yes
Run Code Online (Sandbox Code Playgroud)
或者:点击Shift+ f,然后选择显示按内存使用顺序点按键n然后按Enter.您将看到按内存使用情况排序的活动进程
sar*_*old 274
首先,重复这个咒语一段时间:"未使用的内存是浪费的内存".Linux内核保持周围巨大的文件元数据并要求提供的文件量,直到一些看起来更重要的是推动了数据.这就是为什么你可以运行:
find /home -type f -name '*.mp3'
find /home -type f -name '*.aac'
Run Code Online (Sandbox Code Playgroud)
让第二个find实例以荒谬的速度运行.
Linux只留下一点内存"免费"来处理内存使用量的峰值而不需要太多努力.
其次,你想要找到满足你所有记忆的过程; 在top使用M命令按内存使用排序.您可以随意忽略该VIRT列,它只会告诉您已分配了多少虚拟内存,而不是该进程正在使用多少内存.RES报告多少内存驻留,或目前在RAM(而不是交换到磁盘或从不摆在首位,尽管被要求实际分配).
但是,由于几乎每个进程RES都会计算/lib/libc.so.6一次内存,因此对于进程使用的内存量来说,这并不是一个很好的衡量标准.该SHR列报告了与其他进程共享多少内存,但无法保证另一个进程实际共享 - 它可以是可共享的,只是没有其他人想要共享.
该smem工具旨在帮助用户更好地规到底有多少内存应该真正对每一道工序进行指责.它做了一些聪明的工作来弄清楚什么是真正独特的,共享的,并按比例计算共享内存与共享内存的进程.smem可以帮助你了解你的记忆力比你想要的更好top,但是它top是一个很好的第一个工具.
小智 37
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10
Run Code Online (Sandbox Code Playgroud)
(在sort命令中添加-n数字标志.)
thk*_*ala 28
首先你应该阅读关于输出的解释free.底线:进程可以使用至少10.7 GB的内存.
然后你应该定义一个进程的"内存使用"(它不容易或不明确,相信我).
然后我们可以帮助更多:-)
Tom*_*Jr. 21
按内存使用列出和排序进程:
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS
Run Code Online (Sandbox Code Playgroud)
Cir*_*四事件 17
ps aux --sort '%mem'
从procps的ps(默认在Ubuntu 12.04上)生成输出,如:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
...
tomcat7 3658 0.1 3.3 1782792 124692 ? Sl 10:12 0:25 /usr/lib/jvm/java-7-oracle/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -D
root 1284 1.5 3.7 452692 142796 tty7 Ssl+ 10:11 3:19 /usr/bin/X -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
ciro 2286 0.3 3.8 1316000 143312 ? Sl 10:11 0:49 compiz
ciro 5150 0.0 4.4 660620 168488 pts/0 Sl+ 11:01 0:08 unicorn_rails worker[1] -p 3000 -E development -c config/unicorn.rb
ciro 5147 0.0 4.5 660556 170920 pts/0 Sl+ 11:01 0:08 unicorn_rails worker[0] -p 3000 -E development -c config/unicorn.rb
ciro 5142 0.1 6.3 2581944 239408 pts/0 Sl+ 11:01 0:17 sidekiq 2.17.8 gitlab [0 of 25 busy]
ciro 2386 3.6 16.0 1752740 605372 ? Sl 10:11 7:38 /usr/lib/firefox/firefox
Run Code Online (Sandbox Code Playgroud)
所以这里的Firefox是最重要的消费者,拥有16%的内存.
您也可能对...有兴趣:
ps aux --sort '%cpu'
Run Code Online (Sandbox Code Playgroud)
基于gaoithe 的 回答,我尝试使内存单位以兆字节为单位显示,并按内存降序排序,限制为 15 个条目:
ps -e -orss=,args= |awk '{print $1 " " $2 }'| awk '{tot[$2]+=$1;count[$2]++} END {for (i in tot) {print tot[i],i,count[i]}}' | sort -n | tail -n 15 | sort -nr | awk '{ hr=$1/1024; printf("%13.2fM", hr); print "\t" $2 }'
588.03M /usr/sbin/apache2
275.64M /usr/sbin/mysqld
138.23M vim
97.04M -bash
40.96M ssh
34.28M tmux
17.48M /opt/digitalocean/bin/do-agent
13.42M /lib/systemd/systemd-journald
10.68M /lib/systemd/systemd
10.62M /usr/bin/redis-server
8.75M awk
7.89M sshd:
4.63M /usr/sbin/sshd
4.56M /lib/systemd/systemd-logind
4.01M /usr/sbin/rsyslogd
Run Code Online (Sandbox Code Playgroud)
以下是在 bash 配置文件中使用它的示例别名:
alias topmem="ps -e -orss=,args= |awk '{print \$1 \" \" \$2 }'| awk '{tot[\$2]+=\$1;count[\$2]++} END {for (i in tot) {print tot[i],i,count[i]}}' | sort -n | tail -n 15 | sort -nr | awk '{ hr=\$1/1024; printf(\"%13.2fM\", hr); print \"\t\" \$2 }'"
Run Code Online (Sandbox Code Playgroud)
topmem然后你只需在命令行中输入即可。
如何按进程名称总计使用的内存:
有时即使查看最大的单个进程,仍然有很多未使用的内存。要检查是否有许多相同的较小进程使用内存,您可以使用如下命令,该命令使用 awk 来总结同名进程使用的总内存:
ps -e -orss=,args= |awk '{print $1 " " $2 }'| awk '{tot[$2]+=$1;count[$2]++} END {for (i in tot) {print tot[i],i,count[i]}}' | sort -n
Run Code Online (Sandbox Code Playgroud)
例如输出
9344 docker 1
9948 nginx: 4
22500 /usr/sbin/NetworkManager 1
24704 sleep 69
26436 /usr/sbin/sshd 15
34828 -bash 19
39268 sshd: 10
58384 /bin/su 28
59876 /bin/ksh 29
73408 /usr/bin/python 2
78176 /usr/bin/dockerd 1
134396 /bin/sh 84
5407132 bin/naughty_small_proc 1432
28061916 /usr/local/jdk/bin/java 7
Run Code Online (Sandbox Code Playgroud)