Process Holding the YUM Lock?

Have a server that will not let you run yum, and keeps waiting on another process instead? I had this happen today. Yum sat there printing Another app is currently holding the yum lock; waiting for it to exit… and never got anywhere. Here is the quick fix, plus how to check that it is safe to use it.

Why yum takes a lock

Yum writes its process ID to /var/run/yum.pid while it works, so two package transactions can never change the RPM database at the same time. Any other yum run sees that file and waits. Normally the file goes away when yum finishes. If yum was killed, crashed or the box lost power mid-run, the file can be left behind, and every later yum command waits on a process that no longer exists.

Prerequisites

  • Root access (log in and su to root, or use sudo).
  • CentOS/RHEL 5, 6 or 7 with the classic yum. Newer releases use dnf, covered further down.

1. Check whether something really is running yum

Before deleting anything, see who owns the lock. Yum usually names the other application and its PID in the waiting message. You can also check directly:

cat /var/run/yum.pid
ps -fp $(cat /var/run/yum.pid)
ps aux | grep -E 'yum|packagekit' | grep -v grep

If a real yum, yum-cron or PackageKit process shows up, it is doing work. Let it finish, or stop it cleanly (on CentOS 7, systemctl stop packagekit stops the desktop update service). Only treat the lock as stale when no matching process exists.

2. Remove the stale yum.pid

Here was the solution:

cd /var/run
ls

You should see a yum.pid file in the listing. Remove it:

rm -f yum.pid

3. Clean the yum cache

From there run:

yum clean all

This deletes the cached repository metadata and downloaded packages under /var/cache/yum. It is not strictly needed to release the lock, but a run that was interrupted can leave half-downloaded metadata behind, and cleaning makes yum fetch it fresh.

Viola! Issue has been resolved!

Verify

yum repolist
yum check-update

Both should run straight away without the waiting message. yum check-update exits with code 100 when updates are available, which is normal.

Troubleshooting

  • The lock comes back right away: something is starting yum on a schedule. Look for yum-cron, PackageKit or a configuration management agent, and let it finish.
  • yum was killed in the middle of a transaction: install yum-utils and run yum-complete-transaction to finish or roll back the unfinished transaction, then package-cleanup --problems and package-cleanup --dupes to look for broken or duplicate packages. See Fixing Broken Packages Linux for more.
  • rpmdb errors after a crash (for example “rpmdb open failed”): back up /var/lib/rpm first, then run rpm --rebuilddb.

RHEL, AlmaLinux and Rocky Linux 8, 9 and 10

On these releases yum is a link to dnf, and dnf handles its own locks. When another package process is running, dnf prints a message such as Waiting for process with pid 1234 to finish. Check that PID with ps -fp 1234. It is usually PackageKit, dnf-automatic or another admin’s session. Let it finish or stop that service; you should not need to delete lock files by hand. The cache command is the same idea:

dnf clean all
dnf check-update

Related guides: Fixing Broken Packages Linux | Patching and Installing Updates on CentOS

Leave a Reply

Your email address will not be published. Required fields are marked *