亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

如何在 Linux 中找出內存消耗最大的進程

 

很多次,你可能遇見過系統消耗了過多的內存。如果是這種情況,那么最好的辦法是識別出 linux 機器上消耗過多內存的進程。

-- Magesh Maruthamuthu(作者)

很多次,你可能遇見過系統消耗了過多的內存。如果是這種情況,那么最好的辦法是識別出 Linux 機器上消耗過多內存的進程。我相信,你可能已經運行了下文中的命令以進行檢查。如果沒有,那你嘗試過哪些其他的命令?我希望你可以在評論中更新這篇文章,它可能會幫助其他用戶。

使用 top 命令 和 ps 命令 可以輕松的識別這種情況。我過去經常同時使用這兩個命令,兩個命令得到的結果是相同的。所以我建議你從中選擇一個喜歡的使用就可以。

1) 如何使用 ps 命令在 Linux 中查找內存消耗最大的進程

ps 命令用于報告當前進程的快照。ps 命令的意思是“進程狀態”。這是一個標準的 Linux 應用程序,用于查找有關在 Linux 系統上運行進程的信息。

它用于列出當前正在運行的進程及其進程 ID(PID)、進程所有者名稱、進程優先級(PR)以及正在運行的命令的絕對路徑等。

下面的 ps 命令格式為你提供有關內存消耗最大進程的更多信息。

# ps aux --sort -rss | head
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
MySQL 1064 3.2 5.4 886076 209988 ? Ssl Oct25 62:40 /usr/sbin/mysqld
varnish 23396 0.0 2.9 286492 115616 ? SLl Oct25 0:42 /usr/sbin/varnishd -P /var/run/varnish.pid -f /etc/varnish/default.vcl -a :82 -T 127.0.0.1:6082 -S /etc/varnish/secret -s malloc,256M
named 1105 0.0 2.7 311712 108204 ? Ssl Oct25 0:16 /usr/sbin/named -u named -c /etc/named.conf
nobody 23377 0.2 2.3 153096 89432 ? S Oct25 4:35 Nginx: worker process
nobody 23376 0.1 2.1 147096 83316 ? S Oct25 2:18 nginx: worker process
root 23375 0.0 1.7 131028 66764 ? Ss Oct25 0:01 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nobody 23378 0.0 1.6 130988 64592 ? S Oct25 0:00 nginx: cache manager process
root 1135 0.0 0.9 86708 37572 ? S 05:37 0:20 cwpsrv: worker process
root 1133 0.0 0.9 86708 37544 ? S 05:37 0:05 cwpsrv: worker process

使用以下 ps 命令格式可在輸出中僅展示有關內存消耗過程的特定信息。

# ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head
 PID PPID %MEM %CPU CMD
 1064 1 5.4 3.2 /usr/sbin/mysqld
23396 23386 2.9 0.0 /usr/sbin/varnishd -P /var/run/varnish.pid -f /etc/varnish/default.vcl -a :82 -T 127.0.0.1:6082 -S /etc/varnish/secret -s malloc,256M
 1105 1 2.7 0.0 /usr/sbin/named -u named -c /etc/named.conf
23377 23375 2.3 0.2 nginx: worker process
23376 23375 2.1 0.1 nginx: worker process
 3625 977 1.9 0.0 /usr/local/bin/php-cgi /home/daygeekc/public_html/index.php
23375 1 1.7 0.0 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
23378 23375 1.6 0.0 nginx: cache manager process
 1135 3034 0.9 0.0 cwpsrv: worker process

如果你只想查看命令名稱而不是命令的絕對路徑,請使用下面的 ps 命令格式。

# ps -eo pid,ppid,%mem,%cpu,comm --sort=-%mem | head
 PID PPID %MEM %CPU COMMAND
 1064 1 5.4 3.2 mysqld
23396 23386 2.9 0.0 cache-main
 1105 1 2.7 0.0 named
23377 23375 2.3 0.2 nginx
23376 23375 2.1 0.1 nginx
23375 1 1.7 0.0 nginx
23378 23375 1.6 0.0 nginx
 1135 3034 0.9 0.0 cwpsrv
 1133 3034 0.9 0.0 cwpsrv

2) 如何使用 top 命令在 Linux 中查找內存消耗最大的進程

Linux 的 top 命令是用來監視 Linux 系統性能的最好和最知名的命令。它在交互界面上顯示運行的系統進程的實時視圖。但是,如果要查找內存消耗最大的進程,請 在批處理模式下使用 top 命令 。

你應該正確地 了解 top 命令輸出 以解決系統中的性能問題。

# top -c -b -o +%MEM | head -n 20 | tail -15
 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
 1064 mysql 20 0 886076 209740 8388 S 0.0 5.4 62:41.20 /usr/sbin/mysqld
23396 varnish 20 0 286492 115616 83572 S 0.0 3.0 0:42.24 /usr/sbin/varnishd -P /var/run/varnish.pid -f /etc/varnish/default.vcl -a :82 -T 127.0.0.1:6082 -S /etc/varnish/secret -s malloc,256M
 1105 named 20 0 311712 108204 2424 S 0.0 2.8 0:16.41 /usr/sbin/named -u named -c /etc/named.conf
23377 nobody 20 0 153240 89432 2432 S 0.0 2.3 4:35.74 nginx: worker process
23376 nobody 20 0 147096 83316 2416 S 0.0 2.1 2:18.09 nginx: worker process
23375 root 20 0 131028 66764 1616 S 0.0 1.7 0:01.07 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
23378 nobody 20 0 130988 64592 592 S 0.0 1.7 0:00.51 nginx: cache manager process
 1135 root 20 0 86708 37572 2252 S 0.0 1.0 0:20.18 cwpsrv: worker process
 1133 root 20 0 86708 37544 2212 S 0.0 1.0 0:05.94 cwpsrv: worker process
 3034 root 20 0 86704 36740 1452 S 0.0 0.9 0:00.09 cwpsrv: master process /usr/local/cwpsrv/bin/cwpsrv
 1067 nobody 20 0 1356200 31588 2352 S 0.0 0.8 0:56.06 /usr/local/Apache/bin/httpd -k start
 977 nobody 20 0 1356088 31268 2372 S 0.0 0.8 0:30.44 /usr/local/apache/bin/httpd -k start
 968 nobody 20 0 1356216 30544 2348 S 0.0 0.8 0:19.95 /usr/local/apache/bin/httpd -k start

如果你只想查看命令名稱而不是命令的絕對路徑,請使用下面的 top 命令格式。

# top -b -o +%MEM | head -n 20 | tail -15
 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
 1064 mysql 20 0 886076 210340 8388 S 6.7 5.4 62:40.93 mysqld
23396 varnish 20 0 286492 115616 83572 S 0.0 3.0 0:42.24 cache-main
 1105 named 20 0 311712 108204 2424 S 0.0 2.8 0:16.41 named
23377 nobody 20 0 153240 89432 2432 S 13.3 2.3 4:35.74 nginx
23376 nobody 20 0 147096 83316 2416 S 0.0 2.1 2:18.09 nginx
23375 root 20 0 131028 66764 1616 S 0.0 1.7 0:01.07 nginx
23378 nobody 20 0 130988 64592 592 S 0.0 1.7 0:00.51 nginx
 1135 root 20 0 86708 37572 2252 S 0.0 1.0 0:20.18 cwpsrv
 1133 root 20 0 86708 37544 2212 S 0.0 1.0 0:05.94 cwpsrv
 3034 root 20 0 86704 36740 1452 S 0.0 0.9 0:00.09 cwpsrv
 1067 nobody 20 0 1356200 31588 2352 S 0.0 0.8 0:56.04 httpd
 977 nobody 20 0 1356088 31268 2372 S 0.0 0.8 0:30.44 httpd
 968 nobody 20 0 1356216 30544 2348 S 0.0 0.8 0:19.95 httpd

3) 獎勵技巧:如何使用 ps_mem 命令在 Linux 中查找內存消耗最大的進程

ps_mem 程序 用于顯示每個程序(而不是每個進程)使用的核心內存。該程序允許你檢查每個程序使用了多少內存。它根據程序計算私有和共享內存的數量,并以最合適的方式返回已使用的總內存。

它使用以下邏輯來計算內存使用量。總內存使用量 = sum(用于程序進程的專用內存使用量) + sum(用于程序進程的共享內存使用量)。

# ps_mem
 Private + Shared = RAM used Program
128.0 KiB + 27.5 KiB = 155.5 KiB agetty
228.0 KiB + 47.0 KiB = 275.0 KiB atd
284.0 KiB + 53.0 KiB = 337.0 KiB irqbalance
380.0 KiB + 81.5 KiB = 461.5 KiB dovecot
364.0 KiB + 121.5 KiB = 485.5 KiB log
520.0 KiB + 65.5 KiB = 585.5 KiB auditd
556.0 KiB + 60.5 KiB = 616.5 KiB systemd-udevd
732.0 KiB + 48.0 KiB = 780.0 KiB crond
296.0 KiB + 524.0 KiB = 820.0 KiB avahi-daemon (2)
772.0 KiB + 51.5 KiB = 823.5 KiB systemd-logind
940.0 KiB + 162.5 KiB = 1.1 MiB dbus-daemon
 1.1 MiB + 99.0 KiB = 1.2 MiB pure-ftpd
 1.2 MiB + 100.5 KiB = 1.3 MiB master
 1.3 MiB + 198.5 KiB = 1.5 MiB pickup
 1.3 MiB + 198.5 KiB = 1.5 MiB bounce
 1.3 MiB + 198.5 KiB = 1.5 MiB pipe
 1.3 MiB + 207.5 KiB = 1.5 MiB qmgr
 1.4 MiB + 198.5 KiB = 1.6 MiB cleanup
 1.3 MiB + 299.5 KiB = 1.6 MiB trivial-rewrite
 1.5 MiB + 145.0 KiB = 1.6 MiB config
 1.4 MiB + 291.5 KiB = 1.6 MiB tlsmgr
 1.4 MiB + 308.5 KiB = 1.7 MiB local
 1.4 MiB + 323.0 KiB = 1.8 MiB anvil (2)
 1.3 MiB + 559.0 KiB = 1.9 MiB systemd-journald
 1.8 MiB + 240.5 KiB = 2.1 MiB proxymap
 1.9 MiB + 322.5 KiB = 2.2 MiB auth
 2.4 MiB + 88.5 KiB = 2.5 MiB systemd
 2.8 MiB + 458.5 KiB = 3.2 MiB smtpd
 2.9 MiB + 892.0 KiB = 3.8 MiB bash (2)
 3.3 MiB + 555.5 KiB = 3.8 MiB NetworkManager
 4.1 MiB + 233.5 KiB = 4.3 MiB varnishd
 4.0 MiB + 662.0 KiB = 4.7 MiB dhclient (2)
 4.3 MiB + 623.5 KiB = 4.9 MiB rsyslogd
 3.6 MiB + 1.8 MiB = 5.5 MiB sshd (3)
 5.6 MiB + 431.0 KiB = 6.0 MiB polkitd
 13.0 MiB + 546.5 KiB = 13.6 MiB tuned
 22.5 MiB + 76.0 KiB = 22.6 MiB lfd - sleeping
 30.0 MiB + 6.2 MiB = 36.2 MiB php-fpm (6)
 5.7 MiB + 33.5 MiB = 39.2 MiB cwpsrv (3)
 20.1 MiB + 25.3 MiB = 45.4 MiB httpd (5)
104.7 MiB + 156.0 KiB = 104.9 MiB named
112.2 MiB + 479.5 KiB = 112.7 MiB cache-main
 69.4 MiB + 58.6 MiB = 128.0 MiB nginx (4)
203.4 MiB + 309.5 KiB = 203.7 MiB mysqld
---------------------------------
 775.8 MiB
=================================

via: https://www.2daygeek.com/linux-find-top-memory-consuming-processes/

作者: Magesh Maruthamuthu 選題: lujun9972 譯者: lnrCoder 校對: wxy

本文由 LCTT 原創編譯, Linux中國 榮譽推出

分享到:
標簽:內存 Linux
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定