process-cleanup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseProcess Cleanup
进程清理
Detect and reap zombie processes using .
/bin/ps使用检测并收割僵尸进程。
/bin/psBackground
背景知识
A zombie (state ) is a process that has exited but whose parent hasn't called to collect its exit status. Zombies consume no CPU or memory, but they hold a PID slot and can accumulate. You can't a zombie — it's already dead. The only remedies are:
Zwait()kill- Signal the parent with so it reaps the child
SIGCHLD - Kill the parent so /
initadopts and reaps the orphanlaunchd
僵尸进程(状态为)是指已经退出但父进程尚未调用来收集其退出状态的进程。僵尸进程不消耗CPU或内存,但会占用PID槽位,并且可能会累积。你无法僵尸进程——它已经死了。唯一的解决方法是:
Zwait()kill- 向父进程发送信号,使其收割子进程
SIGCHLD - 杀死父进程,让/
init接管并收割孤儿进程launchd
Important: use ps
for process state queries
ps重要提示:使用ps
进行进程状态查询
psAlways use (BSD) for process state queries. If is aliased, use to bypass it.
psps/bin/psbash
undefined始终使用(BSD版本)进行进程状态查询。如果被设置了别名,请使用来绕过别名。
psps/bin/psbash
undefinedList zombies
列出僵尸进程
/bin/ps ax -o pid,state,ppid,user,command | awk '$2 ~ /Z/'
/bin/ps ax -o pid,state,ppid,user,command | awk '$2 ~ /Z/'
List all processes with state
列出所有带状态的进程
/bin/ps ax -o pid,state,ppid,etime,args
undefined/bin/ps ax -o pid,state,ppid,etime,args
undefinedUsage
使用方法
Run the helper script to scan for zombies:
bash
undefined运行辅助脚本扫描僵尸进程:
bash
undefinedDetect only (default) — list zombie processes
仅检测(默认模式)——列出僵尸进程
bash scripts/kill-zombies.sh
bash scripts/kill-zombies.sh
Reap zombies — send SIGCHLD to parent processes
收割僵尸进程——向父进程发送SIGCHLD信号
bash scripts/kill-zombies.sh --kill
undefinedbash scripts/kill-zombies.sh --kill
undefinedSafety
安全说明
- Default mode is detect-only — no processes are signaled
- With , the script sends
--killto parent processes (non-destructive nudge to reap)SIGCHLD - If a parent ignores , the script reports the parent PID — confirm with the user before killing it
SIGCHLD - Never kill PID 1 (/
init)launchd
- 默认模式为仅检测——不会向任何进程发送信号
- 使用参数时,脚本会向父进程发送
--kill信号(这是一种非破坏性的提示,促使其收割僵尸进程)SIGCHLD - 如果父进程忽略信号,脚本会报告父进程的PID——在杀死它之前请先与用户确认
SIGCHLD - 切勿杀死PID为1的进程(/
init)launchd