The process management tool htop that replaces top under linux

1. Introduction to htop

This is htop, an interactive process viewer for Linux. It is a text-mode application (for console or X terminals) and requires ncurses.

Comparison between htop and top

  • In 'htop' you can scroll the list vertically and horizontally to see all processes and complete command lines.
  • In 'top' you are subject to a delay for each unassigned key you press (especially annoying when multi-key escape sequences are triggered by accident).
  • 'htop' starts faster ('top' seems to collect data for a while before displaying anything).
  • In 'htop' you don't need to type the process number to kill a process, in 'top' you do.
  • In 'htop' you don't need to type the process number or the priority value to renice a process, in 'top' you do.
  • 'htop' supports mouse operation, 'top' doesn't
  • 'top' is older, hence, more used and tested.

htop is an interactive process viewer for Linux systems, a text-mode application (in console or X terminal) that requires ncurses.

Compared with the traditional top of Linux, htop is more user-friendly. It allows users to operate interactively, supports color themes, scrolls through the process list horizontally or vertically, and supports mouse operations.

Compared with top, htop has the following advantages:

  • The process list can be scrolled horizontally or vertically to see all processes and the complete command line.
  • On startup, faster than top.
  • You do not need to enter the process ID when killing a process.
  • htop supports mouse operation.
  • top is very old.

htop official website: http://htop.sourceforge.net/

Second, htop installation

a. Source package installation

# tar zxvf htop-1.0.2.tar.gz

# cd htop-1.0.2

# ./configure

1

# make && make install

2

If an error occurs:

configure: error: You may want to use --disable-unicode or install libncursesw.

You need to install ncurses-devel

# yum install ncurses-devel

b. RHEL/CentOS installation

It can be installed by yum install htop, but the premise is to add the yum source of epel. For details, please refer to  the configuration and use of CentOS yum source .

# rpm -ivh http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm 
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL        //导入key 
# yum install htop

三、htop 参数

键入htop 命令,打开htop。

# htop

3

上面左上角显示CPU、内存、交换区的使用情况,右边显示任务、负载、开机时间,下面就是进程实时状况。

下面是 F1~F10 的功能和对应的字母快捷键。

Shortcut Key Function Key Description 中文说明
h, ? F1 Invoke htop Help 查看htop使用说明
S F2 Htop Setup Menu htop 设定
/ F3 Search for a Process 搜索进程
\ F4 Incremental process filtering 增量进程过滤器
t F5 Tree View 显示树形结构
<, > F6 Sort by a column 选择排序方式
[ F7 Nice - (change priority) 可减少nice值,这样就可以提高对应进程的优先级
] F8 Nice + (change priority) 可增加nice值,这样就可以降低对应进程的优先级
k F9 Kill a Process 可对进程传递信号
q F10 Quit htop 结束htop

命令行选项(COMMAND-LINE OPTIONS)

-C --no-color        使用一个单色的配色方案

-d --delay=DELAY     设置延迟更新时间,单位秒

-h --help           显示htop 命令帮助信息

-u --user=USERNAME    只显示一个给定的用户的过程

-p --pid=PID,PID…       只显示给定的PIDs

-s --sort-key COLUMN     依此列来排序

-v –version          显示版本信息

交互式命令(INTERACTIVE COMMANDS)

上下键或PgUP, PgDn 选定想要的进程,左右键或Home, End 移动字段,当然也可以直接用鼠标选定进程;

Space    标记/取消标记一个进程。命令可以作用于多个进程,例如 "kill",将应用于所有已标记的进程

U    取消标记所有进程

s    选择某一进程,按s:用strace追踪进程的系统调用

l    显示进程打开的文件: 如果安装了lsof,按此键可以显示进程所打开的文件

I    倒转排序顺序,如果排序是正序的,则反转成倒序的,反之亦然

+, -    When in tree view mode, expand or collapse subtree. When a subtree is collapsed a "+" sign shows to the left of the process name.

a (在有多处理器的机器上)    设置 CPU affinity: 标记一个进程允许使用哪些CPU

u    显示特定用户进程

   按Memory 使用排序

P    按CPU 使用排序

   按Time+ 使用排序

F    跟踪进程: 如果排序顺序引起选定的进程在列表上到处移动,让选定条跟随该进程。这对监视一个进程非常有用:通过这种方式,你可以让一个进程在屏幕上一直可见。使用方向键会停止该功能。

K    显示/隐藏内核线程

   显示/隐藏用户线程

Ctrl-L    刷新

Numbers    PID 查找: 输入PID,光标将移动到相应的进程上

四、htop 使用

4.1. 显示自带帮助

鼠标点击Help或者按F1 显示自带帮助

4

4.2. htop 设定

鼠标点击Setup或者按下F2 之后进入htop 设定的页面,Meters 页面设定了顶端的一些信息显示,顶端的显示又分为左右两侧,到底能显示些什么可以在最右侧那栏新增,要新增到上方左侧(F5)或是右侧(F6)都可以,这就是个人设定的范围了。这里多加了一个时钟。

8

上方左右两栏的显示方式分为Text Bar Graph Led 四种,下图我就把 cpu memory swap 改成文本模式显示,然后右栏的改成Bar 显示,clock 用LED方式显示。数据显示都差不多,只是这样看有点不习惯了。

9

关于Display options 的设定,可要根据管理者自己的需要来设定。

10

颜色选择,除了基本的颜色显示之外,htop 还提供了换面板的功能,其实也只是改变一些色彩显示的设定,虽然说不能自定义到细部的颜色显示,但是至少提供了几种风格可以选择。

11

最后一项的设定是调整 Columns 的显示,就是在一般htop 指令进来希望可以看到的什么样的数据及信息,字段的调整可以在这边做个人化的设定,一般使用系统默认值就好了。

12

4.3. Search Process

Click Search with the mouse or press F3 or enter "/", enter the process name to search, such as search for ssh

5

4.4. Filters

Press F4 to enter the filter, which is equivalent to keyword search, case-insensitive, such as filtering dev

15

4.5. Displaying the tree structure

Enter "t" or press F5 to display the tree structure, which means similar to pstree. You can see the tree-like execution structure of all programs, which is very convenient for system management. To clarify how the program is generated, of course, the tree-like structure The browsing of structures can also be sorted by other data.

6

4.6. Choosing a Sort Method

Press F6 to choose what to sort by, and the most frequently sorted content is cpu and memory!

13

4.7 Operation process

F7 and F8 correspond to nice- and nice+ respectively, and F9 corresponds to kill to send a signal to the process. After selecting the signal, press Enter and it is OK

14

4.8. Display the process of a user, select the user on the left

Enter "u" and select the user on the left

7

aka top

Maybe you are used to top, we can also use top to open htop.

Edit the /root/.bashrc file and add the following code

if [ -f /usr/local/bin/htop ]; then
    alias top=’/usr/local/bin/htop’
be

# source /root/.bashrc

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326535639&siteId=291194637