以下是在 Ubuntu 和 CentOS 系统上安装和使用 htop 的详细步骤:
一、在 Ubuntu 上安装和使用 htop
1. 安装 htop
# 更新软件包列表sudo apt update# 安装 htopsudo apt install htop -y
2. 使用 htop
# 启动 htop(实时监控进程)htop# 常用参数示例:htop -u <用户名> # 查看指定用户的进程htop -p <PID> # 监控指定进程(替换为实际PID)
操作快捷键:
- 上下键:移动选择进程。
- F2:进入设置界面(自定义颜色、显示列等)。
- F3:搜索进程。
- F5:树形视图显示进程层级。
- F9:向选中的进程发送信号(如
SIGKILL终止进程)。 - F10 或 q:退出 htop。
二、在 CentOS 上安装和使用 htop
1. 安装 htop
CentOS 7 及更早版本
# 启用 EPEL 仓库(提供额外软件包)sudo yum install epel-release -y# 安装 htopsudo yum install htop -y
CentOS 8/RHEL 8 及更新版本
# 启用 PowerTools 仓库(部分系统可能需要)sudo dnf config-manager --set-enabled powertools# 安装 htopsudo dnf install htop -y
2. 使用 htop
# 启动 htop(实时监控进程)htop# 常用参数与 Ubuntu 相同htop -u <用户名> # 查看指定用户的进程htop -p <PID> # 监控指定进程
三、补充说明
无需 root 权限运行
htop默认以当前用户权限运行,但若需查看所有进程(包括其他用户),需使用sudo:sudo htop
界面功能
- 颜色标识:不同颜色代表进程状态(如蓝色为系统进程,绿色为用户进程)。
- 资源占用条:直观显示 CPU、内存使用率。
- 排序:按
F6选择排序方式(如按 CPU、内存或运行时间)。
卸载 htop(可选)
- Ubuntu/Debian:
sudo apt remove htop - CentOS/RHEL:
sudo yum remove htop或sudo dnf remove htop
- Ubuntu/Debian:
常见问题
CentOS 找不到 htop 包?
确保已启用 EPEL 仓库(CentOS 7)或 PowerTools 仓库(CentOS 8+)。htop 显示异常?
尝试重置配置:删除~/.config/htop/htoprc文件后重启。
通过以上步骤,您可以在 Ubuntu 和 CentOS 上轻松安装并使用 htop 进行系统监控!
