Fix dpkg and apt Lock Errors Safely
An apt or dpkg lock usually means another package operation is already protecting the package database. Do not delete the lock file. Identify the owner, let healthy updates finish, terminate only a genuinely frozen frontend, then complete pending configuration and dependency repair.