Merge pull request #28838 from perfiffer/trans

translated by perfiffer
This commit is contained in:
六开箱 2023-03-11 20:50:34 +08:00 committed by GitHub
commit bd673050c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 196 additions and 197 deletions

View File

@ -1,197 +0,0 @@
[#]: subject: "How to Install and Use htop in Linux"
[#]: via: "https://itsfoss.com/use-htop/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: "perfiffer"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to Install and Use htop in 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.
On the command line, the top command is perhaps the goto command for checking the system resource utilization quickly.
[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.
In this guide, I will be showing you how you can install and use htop in Linux.
### Install htop utility in Linux
You wont 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:
```
sudo apt install htop
```
Similarly, if youre on Fedora, you can use the given command:
```
sudo dnf install htop
```
And theres also a snap package available if you like to avoid building packages from the source:
```
sudo snap install htop
```
If youre on something else or want to build from a source, you can always refer to [htops GitHub page][3] for detailed instructions.
Once youre 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
```
![install and use htop][4]
In htop, there is a color coding for the individual section, so lets have a look at what each color indicates while using htop.
##### What different colors and statistics indicate in htop
So lets start with the CPU usage bar, as it utilizes the maximum number of colors.
#### CPU usage bar
![cpu process in htop][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.
#### Memory bar
![memory bar in 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]
- **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.
- **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, lets jump to the actual implementation part.
### How to use htop in Linux
As the htop is mainly used to check for system resources, lets have a look at how you can sort the processes based on resource consumption.
#### Sort processes based on Resource Consumption
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.
Press **F6** and it will bring up every option available to sort the ongoing processes:
![sort processes in htop using keyboard shortcut][8]
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
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:
![search processes in htop][9]
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.
To filter processes, you have to press **F4** and type the name of the process. For example, I filtered processes related to gnome-boxes:
![filter processes in htop][10]
#### Kill process
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:
![kill process in htop][11]
I cant 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.
But I will recommend you use SIGTERM first, as it is the most efficient and friendly way to kill the process.
#### Customize htop
Here, my aim is to add a date and time and change the color scheme to monochrome.
First, press **F2**, and it will being setup prompt allowing users to change how htop looks:
![customize htop in ubuntu][13]
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:
![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:
![explore available meters in htop][15]
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):
![add date and time htop][16]
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
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].
--------------------------------------------------------------------------------
via: https://itsfoss.com/use-htop/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed
[1]: https://itsfoss.com/linux-system-monitoring-tools/
[2]: https://linuxhandbook.com/top-command/
[3]: https://github.com/htop-dev/htop
[4]: https://itsfoss.com/wp-content/uploads/2022/11/install-and-use-htop.png
[5]: https://itsfoss.com/wp-content/uploads/2022/11/cpu-process-in-htop-1.png
[6]: https://itsfoss.com/wp-content/uploads/2022/11/memory-bar-in-htop.png
[7]: https://itsfoss.com/wp-content/uploads/2022/11/task-statistics-in-htop.png
[8]: https://itsfoss.com/wp-content/uploads/2022/11/sort-processes-in-htop-using-keyboard-shortcut.png
[9]: https://itsfoss.com/wp-content/uploads/2022/11/search-processes-in-htop.png
[10]: https://itsfoss.com/wp-content/uploads/2022/11/filter-processes-in-htop.png
[11]: https://itsfoss.com/wp-content/uploads/2022/11/kill-process-in-htop.png
[12]: https://linuxhandbook.com/termination-signals/
[13]: https://itsfoss.com/wp-content/uploads/2022/11/customize-htop-in-ubuntu.png
[14]: https://itsfoss.com/wp-content/uploads/2022/11/change-htop-colors-in-linux.png
[15]: https://itsfoss.com/wp-content/uploads/2022/11/explore-available-meters-in-htop.png
[16]: https://itsfoss.com/wp-content/uploads/2022/11/add-date-and-time-htop.png
[17]: https://linuxhandbook.com/man-pages/

View File

@ -0,0 +1,196 @@
[#]: subject: "How to Install and Use htop in Linux"
[#]: via: "https://itsfoss.com/use-htop/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: "perfiffer"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
如何在 Linux 中安装和使用 htop
======
Windows 有其著名的任务管理器。Linux 有几个 GUI 和 [命令行系统监视器][1]。每个 Linux 系统都带有其中的几个。
在命令行中top 命令可能是用于快速检查系统资源使用情况的 goto 命令。
除了查看进程之外,[使用 top 命令][2]可能会很棘手。这就是 htop 最顶尖的地方。抛开双关语不谈htop 是一个类似于 top 的实用程序,但具有更好和用户友好的界面。
在本指南中,我将向你展示如何在 Linux 中安装和使用 htop。
### 在 Linux 中安装 htop 实用程序
你不会在大多数的 Linux 发行版中找到预安装的 htop但作为最流行的实用程序之一你会在几乎每个 Linux 发行版的默认存储库中找到 htop。
因此,如果你的机器是基于 Debian/Ubuntu 驱动的,则以下命令应该可以完成你的工作:
```
sudo apt install htop
```
类似的,如果你使用的是 Fedora则可以使用以下的命令
```
sudo dnf install htop
```
如果你想避免从源代码构建包,还有一个 snap 包可用:
```
sudo snap install htop
```
如果你使用的是其它的发行版或者想从源代码构建,你可以随时参考 [htop 的 GitHub 页面][3]以获得详细说明。
完成安装后,你只需在终端中使用 htop 命令,它将反映系统中所有正在运行的进程:
```
htop
```
![安装和使用 htop][4]
在 htop 中,每个部分都有颜色编码,所以让我们看看使用 htop 时每种颜色表示什么。
##### htop 中不同的颜色和统计信息表示什么
让我们从 CPU 使用率栏开始,因为它使用了最大数量的颜色。
#### CPU 使用率栏
![htop 中的 cpu 进程][5]
- **绿色:** 用户进程消耗的资源。
- **蓝色:** 表示低优先级线程。
- **红色:** 系统(内核)进程使用的 CPU 资源。
- **水蓝色:** 表示虚拟化进程。
#### 内存使用率栏
![htop 中的内存栏][6]
- **绿色:** 系统进程正在使用的内存。
- **蓝色:** 缓冲页面使用的内存。
- **橙色:** 分配给缓存页面的内存。
#### 统计数据
![htop 中的任务统计][7]
- **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** 表示你登录后运行的时长。
现在,让我们跳到实际的实现部分。
### 如何在 Linux 中使用 htop
由于 htop 主要用于检查系统资源,让我们看看如何根据资源消耗对进程进行排序。
#### 根据资源消耗对进程进行排序
根据 CPU 和内存使用情况对进程进行排序最简单的方法是使用鼠标指针。将光标悬停在 CPU 或内存部分上,然后单击其中任何一个。
在那里你会看到一个三角形的图标 `△`,你可以根据它从最高到最低的资源消耗对进程进行排序:
但是,如果你正在处理远程服务器,你可能无法使用鼠标,在这种情况下,你可以使用键盘快捷键。
**F6**,它将显示每个可用的选项来对正在进行的进程进行排序:
![使用键盘快捷键对 htop 中的进程进行排序][8]
你可以使用方向键选择一个首选的排序选项,然后按 Enter 键,结果应该会如预期的那样反映出来。
#### 搜索特定进程
如果你想查找一个特定的进程及其资源消耗,你可以按 **F3**,它会给你一个搜索提示,如下所示:
![在 htop 中搜索进程][9]
例如,我搜索 htop它用浅橙色高亮显示了进程。你可以按 **F3** 获得下一个结果。
#### 过滤正在运行的进程
虽然搜索可能会让你获得预期的结果,但我发现使用关键字的过滤过程更加有效,因为它提供了一个过程列表。
要过滤进程,你必须按 **F4** 并输入进程的名称。例如,我过滤了与 gnome-boxes 相关的进程:
![在 htop 中过滤进程][10]
#### 杀死进程
一旦找到最耗资源和不必要的进程,你只需按 **F9**,它就会向你显示终止信号:
![在 htop 中杀死进程][11]
我无法涵盖所有的 15 个终止信号,我们有一个关于[不同终止信息][12]的单独指南,因此如果你想了解更多信息,可以参考该指南。
但我会建议你首先使用 SIGTERM因为它是终止进程的最有效和友好的方式。
#### 自定义 htop
在这里,我的目标是添加日期和时间并将配色方案更改为单色。
首先,按 **F2**,它会出现设置提示,允许用户更改 htop 的外观:
![在 ubuntu 中自定义 htop][13]
首先,将鼠标悬停在各个 `Colors` 部分并按 Enter 键,这将允许我们更改配色方案。从那里,选择单色选项并按 Enter 键保存更改:
![在 Linux 中更改 htop 颜色][14]
现在,返回到设置选项,然后使用向左方向键探索可用的仪表:
![探索 htop 中可用的仪表][15]
因为我打算添加日期和时间,所以我必须在找到它的选项后按 Enter 键。
在这里,它允许你将日期和时间放置在左右两列中,你可以使用向上和向下的方向键更改列的顺序。
所以我将日期和时间仪表放在最后一个样式选项中(你可以使用空格键更改样式):
![在 htop 中添加日期和时间][16]
完成日期和时间仪表的对齐后,按 Enter 键保存更改,然后按 **F10** 关闭设置提示。
### 总结
在本指南中,我解释了如何在不同的 Linux 发行版中安装 htop 实用程序,以及如何使用 htop 的一些基本功能来有效的管理系统资源。
但是 htop 可以做更多的事情,要了解更多信息,你可以随时参考它的手册页,我们有一个详细的指南,告诉你如何[在 Linux 中充分利用手册页][17]。
--------------------------------------------------------------------------------
via: https://itsfoss.com/use-htop/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[perfiffer](https://github.com/perfiffer)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed
[1]: https://itsfoss.com/linux-system-monitoring-tools/
[2]: https://linuxhandbook.com/top-command/
[3]: https://github.com/htop-dev/htop
[4]: https://itsfoss.com/wp-content/uploads/2022/11/install-and-use-htop.png
[5]: https://itsfoss.com/wp-content/uploads/2022/11/cpu-process-in-htop-1.png
[6]: https://itsfoss.com/wp-content/uploads/2022/11/memory-bar-in-htop.png
[7]: https://itsfoss.com/wp-content/uploads/2022/11/task-statistics-in-htop.png
[8]: https://itsfoss.com/wp-content/uploads/2022/11/sort-processes-in-htop-using-keyboard-shortcut.png
[9]: https://itsfoss.com/wp-content/uploads/2022/11/search-processes-in-htop.png
[10]: https://itsfoss.com/wp-content/uploads/2022/11/filter-processes-in-htop.png
[11]: https://itsfoss.com/wp-content/uploads/2022/11/kill-process-in-htop.png
[12]: https://linuxhandbook.com/termination-signals/
[13]: https://itsfoss.com/wp-content/uploads/2022/11/customize-htop-in-ubuntu.png
[14]: https://itsfoss.com/wp-content/uploads/2022/11/change-htop-colors-in-linux.png
[15]: https://itsfoss.com/wp-content/uploads/2022/11/explore-available-meters-in-htop.png
[16]: https://itsfoss.com/wp-content/uploads/2022/11/add-date-and-time-htop.png
[17]: https://linuxhandbook.com/man-pages/