執行 yum 時出現 Existing lock /var/run/yum.pid: another copy is running as pid XXXX,重啟無效。原因是上次 yum 進程異常終止殘留 PID 檔,且 yum-updatesd 守護進程仍持有鎖。本文提供標準清理流程。

Loaded plugins: fastestmirror, security
Existing lock /var/run/yum.pid: another copy is running as pid 4733.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum-updatesd-he
Memory : 22 M RSS (249 MB VSZ)
Started: Fri Jul 6 12:18:29 2012 - 53:47 ago
State : Sleeping, pid: 4733
# ps -fp 4733
# kill 4733 # 若仍存活
# rm -f /var/run/yum.pid
# /sbin/service yum-updatesd restart
# 或
# systemctl restart yum-updatesd # CentOS 7+
# yum clean all
# yum makecache
yum-updatesd 為舊版自動更新守護進程,易造成鎖衝突,現代系統建議使用 yum-cron / dnf-automatic / dnf5-automatic 定時任務替代。
# CentOS 6
# chkconfig yum-updatesd off
# service yum-updatesd stop
# yum remove yum-updatesd
# CentOS 7+
# systemctl disable --now yum-updatesd
# yum remove yum-updatesd
flock -n /var/run/yum.pid -c "yum -y install ..." 確保串行。yum clean all 清理快取減少 I/O 競爭。# dnf 使用 /var/run/dnf.pid
# rm -f /var/run/dnf.pid
# systemctl restart dnf-makecache.timer
快速清理 PID 鎖、重啟守護進程、禁用舊式自動更新,讓包管理器恢復正常運作。