mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
translated by perfiffer
This commit is contained in:
parent
0d710199a5
commit
8ba9b5a1e7
@ -7,163 +7,162 @@
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
How to Install and Use htop in Linux
|
||||
|
||||
如何在 Linux 中安装和使用 htop
|
||||
======
|
||||
Windows 有其著名的任务管理器。Linux 有几个 GUI 和 [命令行系统监视器][1]。每个 Linux 系统都带有其中的几个。
|
||||
|
||||
Windows has its famous task manager. Linux has several GUI and [command line system monitors][1]. Every Linux system comes with a couple of them.
|
||||
在命令行中,top 命令可能是用于快速检查系统资源使用情况的goto命令。
|
||||
|
||||
On the command line, the top command is perhaps the goto command for checking the system resource utilization quickly.
|
||||
除了查看进程之外,[使用 top 命令][2]可能会很棘手。这就是 htop 最顶尖的地方。抛开双关语不谈,htop 是一个类似于 top 的实用程序,但具有更好和用户友好的界面。
|
||||
|
||||
[Using top command][2] apart from viewing the processes could be tricky. And this is where htop tops top. Pun aside, htop is a top-like utility but with a better and user-friendly interface.
|
||||
在本指南中,我将向你展示如何在 Linux 中安装和使用 htop。
|
||||
|
||||
In this guide, I will be showing you how you can install and use htop in Linux.
|
||||
### 在 Linux 中安装 htop 实用程序
|
||||
|
||||
### Install htop utility in Linux
|
||||
|
||||
You won’t find htop pre-installed on the majority of Linux distributions but being one of the most popular utilities, you will find htop in default repositories of almost every Linux distro.
|
||||
|
||||
So if your machine is powered by something that is based on Debian/Ubuntu, the following command should get your job done:
|
||||
你不会在大多数的 Linux 发行版中找到预安装的 htop,但作为最流行的实用程序之一,你会在几乎每个 Linux 发行版的默认存储库中找到 htop。
|
||||
|
||||
因此,如果你的机器由基于 Debian/Ubuntu 驱动的,则以下命令应该可以完成你的工作:
|
||||
|
||||
```
|
||||
sudo apt install htop
|
||||
```
|
||||
|
||||
Similarly, if you’re on Fedora, you can use the given command:
|
||||
类似的,如果你使用的是 Fedora,则可以使用以下的命令:
|
||||
|
||||
```
|
||||
sudo dnf install htop
|
||||
```
|
||||
|
||||
And there’s also a snap package available if you like to avoid building packages from the source:
|
||||
如果你想避免从源代码构建包,还有一个 snap 包可用:
|
||||
|
||||
```
|
||||
sudo snap install htop
|
||||
```
|
||||
|
||||
If you’re on something else or want to build from a source, you can always refer to [htop’s GitHub page][3] for detailed instructions.
|
||||
如果你使用的是其它的发行版或者想从源代码构建,你可以随时参考 [htop 的 GitHub 页面][3]以获得详细说明。
|
||||
|
||||
Once you’re done with the installation, you just have to use the htop command in the terminal, and it will reflect all the ongoing processes in your system:
|
||||
完成安装后,你只需在终端中使用 htop 命令,它将反映系统中所有正在运行的进程:
|
||||
|
||||
```
|
||||
htop
|
||||
```
|
||||
|
||||
![install and use htop][4]
|
||||
![安装和使用 htop][4]
|
||||
|
||||
In htop, there is a color coding for the individual section, so let’s have a look at what each color indicates while using htop.
|
||||
在 htop 中,每个部分都有颜色编码,所以让我们看看使用 htop 时每种颜色表示什么。
|
||||
|
||||
##### What different colors and statistics indicate in htop
|
||||
##### htop 中不同的颜色和统计信息表示什么
|
||||
|
||||
So let’s start with the CPU usage bar, as it utilizes the maximum number of colors.
|
||||
让我们从 CPU 使用率栏开始,因为它使用了最大数量的颜色。
|
||||
|
||||
#### CPU usage bar
|
||||
#### CPU 使用率栏
|
||||
|
||||
![cpu process in htop][5]
|
||||
![htop 中的 cpu 进程][5]
|
||||
|
||||
- **Green:** Resources consumed by user processes.
|
||||
- **Blue:** Indicates low-priority threads.
|
||||
- **Red:** CPU resources used by system (kernel) processes.
|
||||
- **Aqua blue:** Indicates virtualized processes.
|
||||
- **绿色:** 用户进程消耗的资源。
|
||||
- **蓝色:** 表示低优先级线程。
|
||||
- **红色:** 系统(内核)进程使用的 CPU 资源。
|
||||
- **水蓝色:** 表示虚拟化进程。
|
||||
|
||||
#### Memory bar
|
||||
#### 内存使用率栏
|
||||
|
||||
![memory bar in htop][6]
|
||||
![htop 中的内存栏][6]
|
||||
|
||||
- **Green:** Memory being utilized by system processes.
|
||||
- **Blue:** Memory used by buffer pages.
|
||||
- **Orange:** Memory allocated for cache pages.
|
||||
- **绿色:** 系统进程正在使用的内存。
|
||||
- **蓝色:** 缓冲页面使用的内存。
|
||||
- **橙色:** 分配给缓存页面的内存。
|
||||
|
||||
#### Statistics
|
||||
#### 统计数据
|
||||
|
||||
![task statistics in htop][7]
|
||||
![htop 中的任务统计][7]
|
||||
|
||||
- **1.86** is the average load for the last minute.
|
||||
- **1.75** is the average load for the last 4 minutes.
|
||||
- **1.47** is the average load for the last 15 minutes.
|
||||
- **1.86** 是最后 1 分钟的平均负载。
|
||||
- **1.75** 是最后 4 分钟的平均负载。
|
||||
- **1.47** 是最后 15 分钟的平均负载。
|
||||
- **Tasks: 166** 表示一共有 166 个正在运行的进程。
|
||||
- **1249 thr** 表示这 166 个进程由 1249 个线程处理。
|
||||
- **1 running** 表示在这 166 个进程中,只有
|
||||
- **The load average** 表示一段时间内的平均系统负载。由于我的系统是 Hexa-Core,所以 6.0 以下的都可以。这个数字可能会超过,比如 6.1,所以即将要运行的进程必须等待正在进行的任务完成。
|
||||
- **Uptime** 表示你登录后运行的时长。
|
||||
|
||||
- **Tasks: 166** shows there is a total of 166 ongoing processes.
|
||||
- **1249 thr** indicates that those 166 processes are handled by 1249 threads.
|
||||
- **1 running** indicates that from those 166 processes, only one task is in a state of running.
|
||||
- **The load** average indicates the average system load over a period of time. Since my system is Hexa-Core, anything under 6.0 is ok. This number may exceed, such as 6.1, so the upcoming processes have to wait for ongoing tasks to be completed.
|
||||
- **Uptime** is nothing but hours since you logged in.
|
||||
现在,让我们跳到实际的实现部分。
|
||||
|
||||
Now, let’s jump to the actual implementation part.
|
||||
### 如何在 Linux 中使用 htop
|
||||
|
||||
### How to use htop in Linux
|
||||
由于 htop 主要用于检查系统资源,让我们看看如何根据资源消耗对进程进行排序。
|
||||
|
||||
As the htop is mainly used to check for system resources, let’s have a look at how you can sort the processes based on resource consumption.
|
||||
#### 根据资源消耗对进程进行排序
|
||||
|
||||
#### Sort processes based on Resource Consumption
|
||||
根据 CPU 和内存使用情况对进程进行排序最简单的方法是使用鼠标指针。将光标悬停在 CPU 或内存部分上,然后单击其中任何一个。
|
||||
|
||||
The easiest way to sort processes based on CPU and memory usage is to use your mouse pointer. Hover the cursor over the CPU or Memory section and click on any of those.
|
||||
在那里你会看到一个三角形的图标 `△`,你可以根据它从最高到最低的资源消耗对进程进行排序:
|
||||
|
||||
And there you will see an icon of a triangle `△` and based on that you can sort the process based on highest to lowest resource consumption:
|
||||
但是,如果你正在处理远程服务器,你可能无法使用鼠标,在这种情况下,你可以使用键盘快捷键。
|
||||
|
||||
But if you are dealing with remote servers, you might not have the privilege to use a mouse and in those cases, you can use keyboard shortcuts.
|
||||
按 **F6**,它将显示每个可用的选项来对正在进行的进程进行排序:
|
||||
|
||||
Press **F6** and it will bring up every option available to sort the ongoing processes:
|
||||
![使用键盘快捷键对 htop 中的进程进行排序][8]
|
||||
|
||||
![sort processes in htop using keyboard shortcut][8]
|
||||
你可以使用方向键选择一个首选的排序选项,然后按 Enter 键,结果应该会如预期的那样反映出来。
|
||||
|
||||
You can use arrow keys to select a preferred sorting option and then press the Enter key, results should reflect as intended.
|
||||
#### 搜索特定进程
|
||||
|
||||
#### Search for a specific process
|
||||
如果你想查找一个特定的进程及其资源消耗,你可以按 **F3**,它会给你一个搜索提示,如下所示:
|
||||
|
||||
If you want to look for a specific process and its resource consumption, you can press **F3** and it will get you a search prompt as shown below:
|
||||
![在 htop 中搜索进程][9]
|
||||
|
||||
![search processes in htop][9]
|
||||
例如,我搜索 htop,它用浅橙色高亮显示了进程。你可以按 **F3** 获得下一个结果。
|
||||
|
||||
For example, I searched for htop, and it highlighted the process with light orange color. And you can press **F3** for the next result.
|
||||
#### 过滤正在运行的进程
|
||||
|
||||
#### Filter ongoing processes
|
||||
虽然搜索可能会让你获得预期的结果,但我发现使用关键字的过滤过程更加有效,因为它提供了一个过程列表。
|
||||
|
||||
While searching may get you the intended results, I find the filtering process using keywords even more effective as it presents a list of processes.
|
||||
要过滤进程,你必须按 **F4** 并输入进程的名称。例如,我过滤了与 gnome-boxes 相关的进程:
|
||||
|
||||
To filter processes, you have to press **F4** and type the name of the process. For example, I filtered processes related to gnome-boxes:
|
||||
![在 htop 中过滤进程][10]
|
||||
|
||||
![filter processes in htop][10]
|
||||
#### 杀死进程
|
||||
|
||||
#### Kill process
|
||||
一旦找到最耗资源和不必要的进程,你只需按 **F9**,它就会向你显示终止信号:
|
||||
|
||||
Once you made it to find the most resource-hungry and unnecessary process, you just have to press **F9**, and it will present you with termination signals:
|
||||
![在 htop 中杀死进程][11]
|
||||
|
||||
![kill process in htop][11]
|
||||
我无法涵盖所有的 15 个终止信号,我们有一个关于[不同终止信息][12]的单独指南,因此如果你想了解更多信息,可以参考该指南。
|
||||
|
||||
I can’t cover all 15 termination signals, we have a separate guide on [different termination signals][12], so you can refer to that guide if you intend to learn more about them.
|
||||
但我会建议你首先使用 SIGTERM,因为它是终止进程的最有效和友好的方式。
|
||||
|
||||
But I will recommend you use SIGTERM first, as it is the most efficient and friendly way to kill the process.
|
||||
#### 自定义 htop
|
||||
|
||||
#### Customize htop
|
||||
在这里,我的目标是添加日期和时间并将配色方案更改为单色。
|
||||
|
||||
Here, my aim is to add a date and time and change the color scheme to monochrome.
|
||||
首先,按 **F2**,它会出现设置提示,允许用户更改 htop 的外观:
|
||||
|
||||
First, press **F2**, and it will being setup prompt allowing users to change how htop looks:
|
||||
![在 ubuntu 中自定义 htop][13]
|
||||
|
||||
![customize htop in ubuntu][13]
|
||||
首先,将鼠标悬停在各个 `Colors` 部分并按 Enter 键,这将允许我们更改配色方案。从那里,选择单色选项并按 Enter 键保存更改:
|
||||
|
||||
First, hover to the `Colors` sections and press Enter and it will allow us to change the color scheme. From there, select the Monochrome option and press Enter to save changes:
|
||||
![在 Linux 中更改 htop 颜色][14]
|
||||
|
||||
![change htop colors in linux][14]
|
||||
现在,返回到设置选项,然后使用向左方向键探索可用的仪表:
|
||||
|
||||
Now, go back to the setup option, and from there, use the left arrow key to explore available meters:
|
||||
![探索 htop 中可用的仪表][15]
|
||||
|
||||
![explore available meters in htop][15]
|
||||
因为我打算添加日期和时间,所以我必须在找到它的选项后按 Enter 键。
|
||||
|
||||
As I intend to add the Date and time, I have to press Enter once I find the option for it.
|
||||
在这里,它允许你将日期和时间放置在左右两列中,你可以使用向上和向下的方向键更改列的顺序。
|
||||
|
||||
Here, it will allow you to place the date and time in any of the left and right columns and you can use the up and down arrow keys to change the order of columns.
|
||||
所以我将日期和时间仪表放在最后一个样式选项中(你可以使用空格键更改样式):
|
||||
|
||||
So I placed the date and time meter with the last styling option (you can change styles using the spacebar):
|
||||
![在 htop 中添加日期和时间][16]
|
||||
|
||||
![add date and time htop][16]
|
||||
完成日期和时间仪表的对齐后,按 Enter 键保存更改,然后按 **F10** 关闭设置提示。
|
||||
|
||||
Once you are done aligning the date and time meter, press the enter key to save changes and **F10** to close the setup prompt.
|
||||
### 总结
|
||||
|
||||
### Wrapping Up
|
||||
在本指南中,我解释了如何在不同的 Linux 发行版中安装 htop 实用程序,以及如何使用 htop 的一些基本功能来有效的管理系统资源。
|
||||
|
||||
In this guide, I explained how you can install the htop utility in different Linux distributions and how you can use some basic functionalities of htop to manage system resources efficiently.
|
||||
|
||||
But htop can do a lot more and for that and to learn more, you can always refer to its man page, and we have a detailed guide on [how you can get the most out of the man page in Linux][17].
|
||||
但是 htop 可以做更多的事情,要了解更多信息,你可以随时参考它的手册页,我们有一个详细的指南,告诉你如何[在 Linux 中充分利用手册页][17]。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -171,7 +170,7 @@ via: https://itsfoss.com/use-htop/
|
||||
|
||||
作者:[Sagar Sharma][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[perfiffer](https://github.com/perfiffer)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
Loading…
Reference in New Issue
Block a user