在 Debian 系统中,监控进程状态的方法很多,既包括命令行工具,也可以通过日志和系统服务进行长期监控。下面按“使用场景”给你一个实用清单。
top(最基础)top
P 按 CPU 排序,M 按内存排序q 退出htop(推荐,更友好)sudo apt install htop
htop
psps aux | grep nginx
或仅看自己进程:
ps -ef
pgrep / pidofpgrep -a nginx
pidof nginx
cat /proc/<pid>/status
包含内存、线程、状态(R/S/D 等)
systemd 服务进程systemctl status nginx
查看:
systemd-cgtop(cgroup 资源)systemd-cgtop
查看服务级 CPU / 内存占用
systemd 自动重启 + 监控编辑服务:
[Service]
Restart=always
RestartSec=5
sudo systemctl daemon-reexec
monit(轻量进程监控)sudo apt install monit
示例监控 nginx:
check process nginx with pidfile /run/nginx.pid
start program = "/usr/sbin/service nginx start"
stop program = "/usr/sbin/service nginx stop"
if failed host 127.0.0.1 port 80 then restart
netstat / ssss -tunlp
查看进程监听端口
lsoflsof -p <pid>
查看进程打开的文件 / 网络连接
journalctljournalctl -u nginx -f
实时查看服务日志
atop:历史资源记录glances:综合监控prometheus + node_exporter:生产环境| 需求 | 推荐 |
|---|---|
| 临时看一眼 | top / htop |
| 看某个进程 | ps / systemctl |
| 服务挂了自动拉起 | systemd + monit |
| 长期运维 | journalctl + monit |
如果你有具体场景(比如:Web 服务、后台脚本、Docker、服务器卡死),我可以给你更针对性的方案。