Linux带有许多用于管理和优化系统的内置工具。如果您是Linux 新手(new to Linux)或刚刚从Windows切换,您需要学习一些命令才能充分利用它。Linux以作为用户或管理员可以完全控制的操作系统而闻名。无论(Whether)您使用 Ubuntu、Mint、Debian还是任何其他Linux 发行版(Linux distribution),您都可以使用正确的命令和工具来做任何事情。
在本文中,我们将重点介绍如何在Linux上检查内存使用情况,因为这是一项重要的技能。有时(Sometimes)应用程序会开始占用所有系统内存,您需要了解查找问题所需采取的故障排除步骤。所以这里有最好的命令行工具来检查你的Linux系统上的内存使用情况。
1. “top”命令
顶级命令行工具将为您提供所有正在运行的进程的摘要。此摘要包含有关内存使用情况的实时信息,因此您也可以将其用作监控应用程序。您可以查看总共使用了多少系统内存,然后您可以浏览进程列表以检查每个进程使用了多少内存。
要运行此工具,只需键入 top 命令:
$ top
top 命令显示您的Linux系统的总内存量和可用内存量以及已使用的物理内存和交换内存。在这种情况下,最重要的列是 % MEM,因为它告诉您每个进程使用了多少物理内存。然后,您可以识别出占用过多内存的流氓应用程序并将其杀死。
此外,您可以使用 top 命令行工具来检查CPU使用率。只需(Just)检查 % CPU列即可查看每个应用程序使用了多少处理能力。
2.“免费”命令
如果您只需要了解系统的内存使用量是可用内存和已用内存的数量,那么您实际上并不需要 top 命令。free 命令就足够了。在终端中输入free并立即了解有多少物理和交换内存可用或使用。同时,您可以获得有关内核使用的缓冲区的信息。
请记住,内存使用信息不会实时显示。您可以使用免费命令行来监控内存使用情况。本质上,这是一个屏幕截图,告诉您在键入命令时有多少可用或使用的内存。如果要监视内存使用情况或了解每个进程使用了多少内存,请使用 top 命令。
3.“htop”命令
htop 命令基本上是顶级命令工具,具有更易于阅读的环境和用户友好的控件。它实时输出RAM使用情况,为您提供所有正在运行的进程的列表,并为您提供控制进程的命令的快捷方式。(RAM)一旦看到占用过多RAM的进程,您可以按快捷键将其杀死,而不是使用Bash命令。
要使用 htop 命令,您需要在终端中键入htop 。也就是说,如果您的Linux发行版默认不附带此工具,您可能会收到错误消息。在这种情况下,键入以下命令进行安装:
$ sudo apt-get install htop
4. “vmstat”命令
vmstat 命令将显示虚拟内存统计报告。该命令将为您提供比您可能需要的更多信息,但如果您打算成为Linux系统管理员,您应该知道它。该报告包括以下信息:
- 以这种方式运行时的进程数(procs)。
- 交换内存、空闲内存、高速缓存和缓冲区的数量。
- 接收并发送到块设备 (IO) 的块。
- CPU时间(用户时间、系统时间、空闲时间)。
在终端中输入vmstat以获取虚拟内存统计报告。
5.检查“proc/meminfo”文件
您可能想知道您的Linux系统从哪里获得所有这些关于RAM使用情况的报告和信息。好吧(Well),到目前为止,您使用的几乎所有命令行工具都具有相同的来源:proc/meminfo 虚拟文件。如果您想直接进入源并获取您想要的所有内存使用信息,您可以通过键入以下命令轻松访问该文件:
less /proc/meminfo
报告很长,因此您应该使用less命令来获得一些导航控制,以便快速扫描输出以查找您需要的数据。也就是说,这份详细的报告包含很多您可能不需要的信息。因此,以下是您应该关注的最重要的价值观:
- 内存总量
- 无记忆
- 内存可用
- 缓冲器
- 缓存
- 交换缓存
- 总交换
- 免掉期
6.使用图形用户界面
Linux纯粹主义者可能反对在命令行工具上使用GUI ,但是有一个(GUI)RAM使用的可视化表示是很棒的。您可以使用Linux System Monitor(Linux System Monitor)应用程序获取所需的所有信息并实时监控系统的内存使用情况。
要使用该应用程序,请在开始菜单的搜索栏中输入“系统监视器”,然后按Enter。系统监视器(System Monitor)有两个我们感兴趣的选项卡:进程和(Processes)资源选项(Resources)卡。
在“进程(Processes)”选项卡中,您可以看到当前在Linux操作系统上运行的所有进程。您可以读取每个单独进程的内存使用情况、CPU使用情况和其他数据。在这里,您可以了解其中一个应用程序是否失控并且使用了过多的RAM。然后,您可以通过右键单击它并选择终止选项从同一窗口终止该进程。
也就是说,如果您只需要了解系统内存和CPU的运行情况,您应该查看“资源(Resources)”选项卡中的图形可视化。
在这里,您可以以图表的形式查看CPU、RAM和网络历史记录。这意味着您可以获得特定时间段内系统内存使用情况的历史数据,并且您还可以实时监控该使用情况。
您更喜欢如何检查Linux操作系统上的内存使用情况?你知道其他可以获取更有价值数据进行分析的命令和工具吗?在下面的评论中让我们知道!
6 Easy Ways to Check Memory Usage on Linux
Lіnux comes with a lot оf built-in tools for аdministering and optimizіng your system. If you’re new to Linux or just recently made the switch from Windows, you need to learn a number of commands to get the most from it. Linux is mostly famous for being an operating system where the user or administrator has full control. Whether you use Ubuntu, Mint, Debian, or any other Linux distribution, you can do anything with the right commands and tools.
In this article, we’re going to focus on how to check memory usage on Linux because this is an important skill to have. Sometimes apps will start hogging all the system memory and you’ll need to know the troubleshooting steps you need to take to find the issue. So here are the best command-line tools to check memory usage on your Linux system.
1. The “top” Command
The top command-line tool will give you a summary of all the running processes. This summary includes real-time information on memory usage, so you can use it as a monitoring app as well. You can see how much of your system memory is used in total and then you can go through the list of processes to check how much of that memory is used by every process.
To run this tool, simply type the top command:
$ top
The top command shows you your Linux system’s total and free amount of memory as well as the used physical and swap memory. The most important column, in this case, is %MEM because it tells you how much physical memory each process used. Then you can identify the rogue app that’s eating too much memory and kill it.
Also, you can use the top command-line tool to check the CPU usage. Just check the %CPU column to see how much processing power is used by each app.
2. The “free” Command
If all you need to learn about your system’s memory usage is the amount of free and used memory, you don’t really need the top command. The free command will be enough. Type free in the terminal and instantly learn how much physical and swap memory is free or used. At the same time, you get information about the buffers that the kernel uses.
Keep in mind that the memory usage information doesn’t appear in real-time. You can use the free command line to monitor memory usage. Essentially, this is a screenshot that tells you how much memory was free or used when you typed the command. Use the top command if you want to monitor memory usage or to learn how much memory each process uses.
3. The “htop” Command
The htop command is basically the top command tool with an easier-to-read environment and user-friendly controls. It outputs RAM usage in real-time, gives you a list of all the running processes, and it gives you shortcuts to commands that control the processes. Once you see the process that eats up too much RAM, you can press the shortcut key to kill it instead of using Bash commands.
To use the htop command, you need to type htop in the terminal. That said, you might get an error if your Linux distribution doesn’t come with this tool by default. In that case, type the following command to install it:
$ sudo apt-get install htop
4. The “vmstat” Command
The vmstat command will display the virtual memory statistics report. The command will give you more information than you probably need, but if you’re planning to become a Linux system admin, you should know it. The report includes the following information:
- The number of processes (procs) that way for run time.
- The amount of swapped memory, free memory, cache, and buffers.
- Blocks received and sent to a block device (IO).
- CPU times (user time, system time, idle time).
Type vmstat in the terminal to get the virtual memory statistics report.
5. Check the “proc/meminfo” File
You’re probably wondering where your Linux system gets all these reports and information on RAM usage. Well, pretty much all of the command line tools you used so far have the same source: the proc/meminfo virtual file. If you want to go directly to the source and get all the memory usage information you want, you can easily access the file by typing the following command:
less /proc/meminfo
The report is quite long, so you should use the less command to get some navigation control to quickly scan through the output for the data you need. That said, this detailed report contains a lot of information you probably don’t need. So here are the most important values you should focus on:
- MemTotal
- MemFree
- MemAvailable
- Buffers
- Cached
- SwapCached
- SwapTotal
- SwapFree
6. Use the GUI
Linux purists might be against using the GUI over command line tools, but having a visual representation of RAM usage is great. You can get all the information you need and monitor your system’s memory usage in real-time by using the Linux System Monitor app.
To use the app, type “System Monitor” in the start menu’s search bar and press Enter. The System Monitor has two tabs we’re interested in: the Processes and Resources tabs.
In the Processes tab, you can see all the processes that are currently running on your Linux operating system. You can read memory usage, CPU usage, and other data for each individual process. This is where you can learn if one of the apps has gone rogue and is using way too much RAM. Then you can kill the process from the same window by right-clicking on it and selecting the kill option.
That said, if all you need is to learn how your system memory and CPU have been behaving, you should check out the graphical visualization in the Resources tab.
Here you can see the CPU, RAM, and network history as a graph. This means you get historical data on your system’s memory usage over a certain period of time and you can also monitor that usage in real-time.
How do you prefer to check memory usage on your Linux operating system? Do you know other commands and tools that can get more valuable data for analysis? Let us know in the comments below!