在 Debian 系统中,进程管理是系统运维和性能调优的重要部分。下面从查看、控制、优先级、守护进程、自动化与故障排查几个方面系统介绍。
ps —— 查看进程快照ps aux
a:所有用户进程u:显示用户信息x:包括无终端进程常用组合:
ps -ef
ps aux --sort=-%cpu | head
top / htop —— 实时查看top
更友好的工具:
sudo apt install htop
htop
pstree —— 进程树pstree
pstree -p
command &
后台运行:
sleep 100 &
jobs
fg %1 # 前台
bg %1 # 后台
kill PID
kill -9 PID # 强制
pkill nginx
killall nginx
nice -n 10 command
-20(最高)到 19(最低)renice -n 5 -p PID
Debian 默认使用 systemd。
systemctl status ssh
sudo systemctl start ssh
sudo systemctl stop ssh
sudo systemctl restart ssh
sudo systemctl enable ssh
sudo systemctl disable ssh
systemctl list-units --type=service
查看限制:
ulimit -a
临时修改:
ulimit -n 65535
永久修改(对登录用户):
/etc/security/limits.conf
lsof -p PID
ss -lntp
netstat -tunlp
uptime
vmstat 1
iostat
监控工具
htopglancesprometheus + node_exporter定时任务
crontab -e
supervisortop
kill PID
kill -9 PID
若仍无法结束,可能是内核态进程或 I/O 阻塞。
| 功能 | 常用命令 |
|---|---|
| 查看进程 | ps, top, htop |
| 控制进程 | kill, pkill, fg/bg |
| 守护进程 | systemctl |
| 优先级 | nice, renice |
| 资源限制 | ulimit |
| 排错 | lsof, ss, journalctl |
如果你愿意,我可以: