在 CentOS(以及大多数 Linux 发行版)中,查看运行进程常用以下几种方式:
ps 命令(最常用)ps
ps -ef
或
ps aux
ps aux:显示用户、CPU、内存、启动时间等ps -ef:显示父子进程关系(PPID)ps aux | grep nginx
top 命令(实时查看)top
q 退出P 按 CPU 排序,按 M 按内存排序htop(更友好,需安装)yum install -y epel-release
yum install -y htop
htop
pstree(进程树)pstree
或
pstree -p
systemctl status nginx
或
pgrep nginx
/proc 目录(底层方式)ls /proc | grep '^[0-9]'
每个数字目录对应一个进程 PID
# 查看内存占用最高的进程
ps aux --sort=-%mem | head
# 查看 CPU 占用最高的进程
ps aux --sort=-%cpu | head
如果你有具体场景(比如“查看 Java 进程”“找出占用 CPU 的进程”),可以告诉我,我给你更精确的命令。