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

Ubuntu 14.04下SSH执行apt full-upgrade超时后进程挂起求助

Fixing Hung apt full-upgrade After SSH Timeout on Ubuntu 14.04

Alright, let's break down how to get your stuck apt process back on track, plus fix the apt-get autoclean error you're seeing.

First: Understand the Process Chain

You ran pstree -psa 3409 to check the hung process—likely, the output shows apt or apt-get waiting on a child process (most often dpkg) that's stuck waiting for user input (like a config file overwrite prompt) or a lock conflict. That's the root of the hang.

The reptyr tool lets you "steal" a running process and attach it to your current SSH terminal. Here's how to use it:

  1. Install reptyr first (it's available in Ubuntu 14.04 repos):
    sudo apt-get install reptyr
    
  2. Attach to the hung apt process (replace 3409 with your actual process ID if needed):
    sudo reptyr 3409
    
    This will pull up the interactive prompt that was causing the hang (e.g., asking if you want to keep your existing config file or replace it). Answer the prompt, and the full-upgrade should resume normally.

Method 2: Resolve Dpkg Lock/Configuration Issues

If reptyr isn't working, or if the hang is due to a stuck dpkg process:

  1. First, kill any stray apt/dpkg processes (be careful here—only kill the ones related to your hung upgrade):
    sudo kill -TERM 3409
    
    Wait a few seconds, then check if the process is gone with ps aux | grep apt.
  2. Remove any leftover lock files (these can block apt/dpkg from running):
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/apt/lists/lock
    sudo rm /var/cache/apt/archives/lock
    
  3. Finish configuring any partially installed packages:
    sudo dpkg --configure -a
    
  4. Once that's done, you can restart the upgrade:
    sudo apt full-upgrade
    

Fixing apt-get autoclean Errors

The autoclean issue is almost always tied to a corrupted cache or leftover locks. Try these steps:

  1. First, ensure no other apt processes are running (use ps aux | grep apt to check).
  2. Clear the full apt cache first:
    sudo apt-get clean
    
  3. Now run autoclean again:
    sudo apt-get autoclean
    
    If this still fails, check the /var/cache/apt/archives/ directory for damaged .deb files—delete any that look corrupted (they might have zero size or incomplete filenames), then retry autoclean.

Prevent This From Happening Again

To avoid losing control of long-running commands like full-upgrade when SSH times out, use a terminal multiplexer like screen:

  1. Install screen:
    sudo apt-get install screen
    
  2. Start a new screen session:
    screen
    
  3. Run your apt full-upgrade inside this session. Even if your SSH connection drops, the process will keep running in the background.
  4. When you reconnect via SSH, reattach to the screen session with:
    screen -r
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:22:20