怎么知道哪个程序占用了太多的内存?

分享于 

5分钟阅读

ubuntu

  繁體

问题

Ubuntu最近一直在崩溃,我认为它内存不足,所以运行了free -m命令,发现内存使用率非常高,我怎么知道哪个程序会导致ubuntu崩溃/耗尽内存?以下是输出:


shafee@shafee-pc:~$ free -m


 total used free shared buffers cached


Mem: 3824 3714 110 0 978 1954


-/+ buffers/cache: 780 3044


Swap: 99 0 99



shafee@shafee-pc:~$ top


top - 02:12:14 up 1:24, 2 users, load average: 0.16, 0.42, 1.49


Tasks: 182 total, 1 running, 181 sleeping, 0 stopped, 0 zombie


Cpu(s): 2.9%us, 1.9%sy, 0.3%ni, 79.3%id, 15.5%wa, 0.0%hi, 0.2%si, 0.0%st


Mem: 3916708k total, 3803848k used, 112860k free, 1002308k buffers


Swap: 102396k total, 0k used, 102396k free, 2001852k cached



 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 


 4200 root 20 0 289m 53m 38m S 2 1.4 1:06.45 Xorg 


 5590 shafee 20 0 19348 1368 956 R 2 0.0 0:00.01 top 


 1 root 20 0 24124 2136 1264 S 0 0.1 0:02.05 init 


 2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd 


 3 root 20 0 0 0 0 S 0 0.0 0:24.23 ksoftirqd/0 


 6 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/0 


 7 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/1 


 9 root 20 0 0 0 0 S 0 0.0 0:00.11 ksoftirqd/1 


 11 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/2 


 13 root 20 0 0 0 0 S 0 0.0 0:03.89 ksoftirqd/2 


 14 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/3 


 16 root 20 0 0 0 0 S 0 0.0 0:00.16 ksoftirqd/3 


 17 root 0 -20 0 0 0 S 0 0.0 0:00.00 cpuset 


 18 root 0 -20 0 0 0 S 0 0.0 0:00.00 khelper 


 19 root 0 -20 0 0 0 S 0 0.0 0:00.00 netns 


 21 root 20 0 0 0 0 S 0 0.0 0:00.01 sync_supers 


shafee@shafee-pc:~$




答案1

Linux内核自己会做很多内存管理,分配超出其实际需要的内存 - 因此,您的真实"可用内存"数量为3044,"free"中+/- Buffers/cache行的列里,因此实际仅消耗780 MB。

默认情况下,top将根据CPU消耗排序,你可以按Shift+M按所占用内存的百分比进行排序,这样可以更好地了解软件使用分配给内核的内存。


free -m


 total used free shared buffers cached


Mem: 7873 3916 3956 0 231 1117


-/+ buffers/cache: 2567 5305


Swap: 12401 0 12401



在top,内存排序:


top - 17:05:18 up 2 days, 1:40, 4 users, load average: 0.21, 0.14, 0.11


Tasks: 237 total, 1 running, 234 sleeping, 0 stopped, 2 zombie


Cpu(s): 1.6%us, 0.8%sy, 0.1%ni, 96.7%id, 0.8%wa, 0.0%hi, 0.0%si, 0.0%st


Mem: 8062420k total, 4013632k used, 4048788k free, 237204k buffers


Swap: 12699644k total, 292k used, 12699352k free, 1144752k cached



 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 


 1632 root 20 0 884m 240m 6532 S 0 3.1 1:20.17 java 


 3911 marco 20 0 1011m 165m 22m S 0 2.1 9:20.62 chrome 


 3852 marco 20 0 770m 162m 45m S 0 2.1 14:59.59 chrome 


 1091 root 20 0 491m 160m 118m S 3 2.0 29:19.44 Xorg 


 1747 marco 20 0 659m 108m 34m S 1 1.4 18:43.92 compiz 


 3964 marco 20 0 1113m 99m 21m S 0 1.3 18:51.88 chrome 


 1759 marco 20 0 668m 94m 21m S 0 1.2 2:27.42 nautilus 


 3046 marco 20 0 788m 86m 26m S 0 1.1 1:22.96 evolution 


 1793 marco 20 0 647m 85m 18m S 0 1.1 0:12.74 shutter 


 1791 marco 20 0 404m 85m 13m S 0 1.1 5:19.51 bitcoin 


 2938 marco 20 0 809m 78m 31m S 0 1.0 1:01.07 empathy 


 9630 marco 20 0 265m 73m 19m S 1 0.9 12:41.52 skype 


 9618 marco 20 0 914m 64m 21m S 0 0.8 1:14.04 chrome 


 1777 marco 20 0 432m 64m 14m S 0 0.8 1:45.96 pastie




答案2

您可以更改进程的优先级以使其运行得更快,例如,如果您要转换视频等。


答案3

可以使用以下脚本查看GNU Linux系统中各个应用程序的总内存使用量

http://www.zyxware.com/articles/4446/show-total-memory-usage-by-each-application-in-your-ubuntu-or-any-gnu-linux-system


答案4

在Kubuntu中,我只需按Ctrl-Esc,然后使用感兴趣的字段对内容进行排序:内存,CPU,

enter image description here



FIND  MEMO  内存  
相关文章