Merge pull request #16156 from lnrCoder/lnrCoder-patch-2

translated
This commit is contained in:
Xingyu.Wang 2019-11-05 12:01:05 +08:00 committed by GitHub
commit aa9d1a93a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,34 +7,34 @@
[#]: via: (https://www.2daygeek.com/linux-find-top-memory-consuming-processes/) [#]: via: (https://www.2daygeek.com/linux-find-top-memory-consuming-processes/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/) [#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
How to Find Out Top Memory Consuming Processes in Linux 如何在 Linux 中找出内存消耗最高的进程
====== ======
You may have seen your system consumes too much of memory many times. 你可能已经见过系统多次消耗过多的内存。
If thats the case, what would be the best thing you can do to identify processes that consume too much memory on a Linux machine. 如果是这种情况,那么最好的办法是识别出 Linux 机器上消耗过多内存的进程。
I believe, you may have run one of the below commands to check it out. 我相信,你可能已经运行了以下命令以进行检查。
If not, what is the other commands you tried? 如果没有,那你尝试过哪些其他的命令?
I would request you to update it in the comment section, it may help other users. 我请求你更新它在评论中进行更新,它可能会帮助其他用户。
This can be easily identified using the **[top command][1]** and the **[ps command][2]**. 使用 **[top 命令][1]** 和 **[ps 命令][2]** 可以轻松的识别。
I used to check both commands simultaneously, and both were given the same result. 我过去经常同时使用这两个命令,两个命令得到的结果是相同的。
So i suggest you to use one of the command that you like. 所以我建议你从中选择一个喜欢的使用就可以。
### 1) How to Find Top Memory Consuming Process in Linux Using the ps Command ### 1) 如何使用 ps 命令在 Linux 中查找内存消耗最大的进程
The ps command is used to report a snapshot of the current processes. The ps command stands for process status. ps 命令用于报告当前进程的快照。ps 命令代表进程状态。
This is a standard Linux application that looks for information about running processes on a Linux system. 这是一个标准的 Linux 应用程序,用于查找有关在 Linux 系统上运行进程的信息。
It is used to list the currently running processes and their process ID (PID), process owner name, process priority (PR), and the absolute path of the running command, etc,. 它用于列出当前正在运行的进程及其进程 IDPID进程所有者名称进程优先级PR以及正在运行的命令的绝对路径等。
The below ps command format provides you more information about top memory consumption process. 下面的 ps 命令格式为你提供有关内存消耗最大进程的更多信息。
``` ```
# ps aux --sort -rss | head # ps aux --sort -rss | head
@ -51,7 +51,7 @@ root 1135 0.0 0.9 86708 37572 ? S 05:37 0:20 cwpsrv: worker
root 1133 0.0 0.9 86708 37544 ? S 05:37 0:05 cwpsrv: worker process root 1133 0.0 0.9 86708 37544 ? S 05:37 0:05 cwpsrv: worker process
``` ```
Use the below ps command format to include only specific information about the process of memory consumption in the output. 使用以下 ps 命令格式可在输出中仅展示有关内存消耗过程的特定信息。
``` ```
# ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head # ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head
@ -68,7 +68,7 @@ Use the below ps command format to include only specific information about the p
1135 3034 0.9 0.0 cwpsrv: worker process 1135 3034 0.9 0.0 cwpsrv: worker process
``` ```
If you want to see only the command name instead of the absolute path of the command, use the ps command format below. 如果你只想查看命令名称而不是命令的绝对路径,请使用下面的 ps 命令格式。
``` ```
# ps -eo pid,ppid,%mem,%cpu,comm --sort=-%mem | head # ps -eo pid,ppid,%mem,%cpu,comm --sort=-%mem | head
@ -85,15 +85,15 @@ If you want to see only the command name instead of the absolute path of the com
1133 3034 0.9 0.0 cwpsrv 1133 3034 0.9 0.0 cwpsrv
``` ```
### 2) How to Find Out Top Memory Consuming Process in Linux Using the top Command ### 2) 如何使用 top 命令在 Linux 中查找内存消耗最大的进程
The Linux top command is the best and most well known command that everyone uses to monitor Linux system performance. Linux 的 top 命令是用来监视 Linux 系统性能的最好和最知名的命令。
It displays a real-time view of the system process running on the interactive interface. 它在交互界面上显示运行的系统进程的实时视图。
But if you want to find top memory consuming process then **[use the top command in the batch mode][3]**. 但是,如果要查找内存消耗最大的进程,请 **[在批处理模式下使用 top 命令][3]**。
You should properly **[understand the top command output][4]** to fix the performance issue in system. 你应该正确地 **[了解 top 命令输出][4]** 以解决系统中的性能问题。
``` ```
# top -c -b -o +%MEM | head -n 20 | tail -15 # top -c -b -o +%MEM | head -n 20 | tail -15
@ -114,7 +114,7 @@ You should properly **[understand the top command output][4]** to fix the perfor
968 nobody 20 0 1356216 30544 2348 S 0.0 0.8 0:19.95 /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
``` ```
If you only want to see the command name instead of the absolute path of the command, use the below top command format. 如果你只想查看命令名称而不是命令的绝对路径,请使用下面的 top 命令格式。
``` ```
# top -b -o +%MEM | head -n 20 | tail -15 # top -b -o +%MEM | head -n 20 | tail -15
@ -135,15 +135,15 @@ If you only want to see the command name instead of the absolute path of the com
968 nobody 20 0 1356216 30544 2348 S 0.0 0.8 0:19.95 httpd 968 nobody 20 0 1356216 30544 2348 S 0.0 0.8 0:19.95 httpd
``` ```
### 3) Bonus Tips: How to Find Out Top Memory Consuming Process in Linux Using the ps_mem Command ### 3) 温馨提示:如何使用 ps_mem 命令在 Linux 中查找内存消耗最大的进程
The **[ps_mem utility][5]** is used to display the core memory used per program (not per process). **[ps_mem 程序][5]** 用于显示每个程序(而不是每个进程)使用的核心内存。
This utility allows you to check how much memory is used per program. 该程序允许你检查每个程序使用了多少内存。
It calculates the amount of private and shared memory against a program and returns the total used memory in the most appropriate way. 它根据程序计算私有和共享内存的数量,并以最合适的方式返回已使用的总内存。
It uses the following logic to calculate RAM usage. Total RAM = sum (private RAM for program processes) + sum (shared RAM for program processes) 它使用以下逻辑来计算内存使用量。 总内存使用量 = 用于程序处理的专用内存使用量 + 用于程序处理的共享内存使用量
``` ```
# ps_mem # ps_mem