How to Fix unattended-upgrades High CPU Usage and DPKG Lock in Ubuntu

In Ubuntu and Debian systems, the unattended-upgrades service runs silently in the background to automatically download and apply critical security patches and package bug fixes. However, when users open a terminal to install software or run sudo apt update only to be blocked by the error “Could not get lock /var/lib/dpkg/lock-frontend – open (11: Resource temporarily unavailable)” while system fans spin up due to 100% CPU usage from python3 /usr/share/unattended-upgrades/unattended-upgrade, workflows halt. Resolving this issue involves safely managing active package locks, configuring update scheduling, and disabling automatic background installations where appropriate.

Check Active Upgrade Status and Wait for Completion

Forcefully terminating unattended-upgrades while it is actively unpacking or configuring Linux kernel packages can corrupt the DPKG package database.

  1. Open a terminal window (press Ctrl + Alt + T).
  2. Check which process currently holds the APT lock:
    ps aux | grep -i apt
  3. Inspect the live unattended-upgrades log to see what it is downloading:
    sudo tail -f /var/log/unattended-upgrades/unattended-upgrades.log
  4. If the service is actively applying updates, wait 2 to 5 minutes for it to finish cleanly. The lock will release automatically once installation completes.

Safely Terminate a Stalled or Frozen Upgrade Process

If the log has not changed for over thirty minutes and the process remains locked in a high-CPU calculation loop, you must terminate the process safely.

  1. Identify the process ID (PID) of the stuck upgrade:
    pgrep -f unattended-upgrade
  2. Send a graceful SIGTERM signal:
    sudo kill -15 $(pgrep -f unattended-upgrade)
  3. Wait thirty seconds. If the process refuses to exit, send a forceful kill signal:
    sudo kill -9 $(pgrep -f unattended-upgrade)
  4. Configure any partially unpacked packages:
    sudo dpkg --configure -a

Release Orphaned DPKG Lock Files

If an upgrade was killed or the computer lost power during a background update, lock files can remain orphaned on the filesystem.

  1. Verify that no APT or DPKG processes are running:
    sudo fuser -v /var/lib/dpkg/lock-frontend
    sudo fuser -v /var/lib/apt/lists/lock
  2. If the output is blank (confirming no active process holds the file), safely remove the residual lock markers:
    sudo rm /var/lib/dpkg/lock-frontend
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/apt/lists/lock
    sudo rm /var/cache/apt/archives/lock
  3. Reconfigure package databases:
    sudo dpkg --configure -a && sudo apt --fix-broken install

Adjust or Disable Automatic Unattended Upgrades

On developer workstations and staging servers, administrators often prefer to trigger updates manually rather than having background daemons lock the package manager unexpectedly.

  1. To completely disable automatic background upgrades via the standard Debian configuration tool:
    sudo dpkg-reconfigure -plow unattended-upgrades
  2. When prompted “Automatically download and install stable updates?”, select No and press Enter.
  3. Alternatively, edit the periodic APT configuration file directly:
    sudo nano /etc/apt/apt.conf.d/20auto-upgrades
  4. Modify the directives to disable automatic installations:
    APT::Periodic::Update-Package-Lists "0";
    APT::Periodic::Unattended-Upgrade "0";
  5. Save the file and exit nano. Automatic background upgrade locks will no longer interrupt your terminal sessions.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.