Wednesday, September 27, 2023
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1739  / 1 Year ago, thu, april 28, 2022, 6:11:27

For some reason we terminate the installation of package via apt-get by pressing ctrl+z,it creates a lock file inside /var/lib/dpkg/ and /var/cache/apt/archives/ directories.

And after that if we want to install another or same package via apt-get,we have to manually remove the lock by running these two commands sudo rm /var/lib/dpkg/lock and sudo rm /var/cache/apt/archives/lock so that the installation will occurs.

My question: Is there any way to remove the lock files automatically that was created after pressing ctrl+z,so that we don't need to remove the lock files manually.

More From » command-line



Because it is not possible for a program to catch SIGSTOP (sent by Ctrl+Z)

To quote the relevant parts of signal(7)Manpage icon:

Signal Value Action Comment
SIGSTOP 17,19,23 Stop Stop process

The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

Therefore, if you stop a progam with Ctrl+Z and close the terminal, it has no chance to perform cleanup (e.g.: removing lock files).

Ctrl+Z should not be used if you intend to cancel an operation, only use it if you intend to pause a program and resume it (or close it cleanly) later.

Thus, Ctrl+C should be used to terminate processes because a program can catch that signal and exit cleanly.

Although, in the case of apt-get, pressing Ctrl+C will leave the lock files behind, but terminate the process. This means that the lock files can be removed, but the package manager could be left in an inconsistent state, if you terminated it at a critical point.

There is really no safe option to terminate apt-get cleanly while it is installing/updating packages, but cancelling (Ctrl-C, then remove lock files) while it's downloading should be fine.

[#27696] Friday, April 29, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 35
Total Questions: 124
Total Answers: 112

Location: Federated States of Micronesia
Member since Sat, Jun 4, 2022
1 Year ago