You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu升级后出现大量僵尸进程问题求助

上周我将Ubuntu从14.04版本升级到18.04版本,起初一切正常。但一两天后,系统出现冻结,无法登录,只能重启。执行ps -ax | grep sh | wc -l命令显示有654个僵尸进程,且数量持续增加;执行ps -elf | grep Z命令发现大量[sshd] 'defunct'进程,其父进程为sh(1)。我查阅了大量资料但均无解决办法,恳请提供帮助。

Hey there, let's tackle this frustrating zombie sshd issue you're facing after upgrading to Ubuntu 18.04. Hundreds of defunct processes piling up and crashing your system is no joke, so let's break down the likely causes and fixes step by step:

1. First, check the biggest red flag: Is PID 1 really sh?

Ubuntu 18.04 uses systemd as its init system, which should always run as PID 1. Systemd is designed to automatically "reap" zombie processes, but a shell (sh) running as PID 1 won't handle this reliably—and that's almost certainly why your zombies are multiplying.

Verify what's running as PID 1 with this command:

ps -p 1 -o comm=

If the output is sh instead of systemd, that's your core problem. Fix it by re-installing the systemd init package:

sudo apt update && sudo apt install --reinstall systemd-sysv

Reboot your system after running this. Once it restarts, recheck PID 1—this time it should show systemd, and zombie processes should stop piling up immediately.

2. Fix sshd session cleanup (if PID 1 is already systemd)

If systemd is already PID 1 but you still see zombie sshd processes, the issue is likely with outdated sshd configuration or PAM (Pluggable Authentication Modules) settings leftover from the 14.04 upgrade:

  • Open your sshd config file for editing:
    sudo nano /etc/ssh/sshd_config
    
    Make sure these critical lines are set correctly:
    UsePAM yes
    PermitUserEnvironment no
    
    These settings ensure PAM handles session cleanup properly. Save the file and restart sshd:
    sudo systemctl restart sshd
    
  • Check sshd logs for clues:
    Look for errors that might explain why sshd processes aren't exiting cleanly:
    sudo tail -f /var/log/auth.log
    
    Keep an eye out for lines about "session cleanup failed", PAM module loading errors, or issues with user session termination.

3. Temporary band-aid (if you can't reboot right now)

If you need to stop the zombie flood immediately before fixing the root cause, send a SIGCHLD signal to the parent sh process (PID 1). This might trigger it to reap existing zombies:

sudo kill -SIGCHLD 1

Note: This is just a temporary fix—you still need to address the underlying issue to prevent zombies from coming back.

4. Verify the fix

After making changes, monitor the zombie process count to ensure it stops growing:

watch -n 5 'ps -elf | grep Z | grep sshd | wc -l'

If the number stays steady or drops to zero, you've resolved the problem.

内容的提问来源于stack exchange,提问作者Mozartos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:25:56