How Linux locks?

Solve the re-occurring could not get lock issue.

Image: Linux Lock. Source:

When you are new to Linux, you might bump into the following errors, and can be frustrating, if you don’t know what actually happened and how to resolve them.

So, take a deep breath and relax, we will try to fix the problem.

Before you try to solve the problem, let me tell you a little bit about how does lock works in Linux systems.

Lock files on Linux are created to avoid race conditions when multiple processes are running.

There are two types of lock:

  1. Exclusive lock
  2. Shared lock

Exclusive lock

When a process holds an exclusive lock on a resource, then it cannot be acquired by other processes until it releases it. This resource cannot acquire by a process whether an exclusive or shared lock on a resource until released.

Shared lock

When a process holds a shared lock, then other processes can acquire the shared lock, but not an exclusive lock on the resource. In short, on shared lock multiple processes can hold multiple resources, whereas exclusive lock is limited to a single process.

You can view all the system locks using lslock command.

Fig: Linux lock. Source: Author

Now, after seeing the above definition and picture, you are aware of why there are lock files in the Linux system.

Let’s try to resolve the issue.

Sometimes you might get the following errors stating

Unable to acquire frontend lock
Resource not available
Cloud not open lock file /var/lib/dpgk/lock-frontend

Example of error: Cloud not open lock file /var/lib/dgpk/lock-frontend

This normally occurs when another apt command is running in the background or synaptic package manager is running or a software update is running.

Fog: Lock Issue. Source: Author

In order to solve this issue, you can use the following series of commands. If. there are no apt or apt-get processes running then it's alright, move to the next step.

Now you should be able to run the commands apt commands like an update, install or upgrade.

Thank you so much for reading this article. I hope after reading this article, you got some understanding of how Linux lock works and how to solve the issue.

If you want to read some more interesting DevOps/ SRE related blogs, here is my website.




DevOps / SRE Engineer. Blog: System admin turned SRE. I love Linux.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Unix Pipes Explained (Introductory)

3 tips to start scaling up successfully your agile delivery.

Programmatically create AEM Translation Projects

DigitalOcean Sponsorship 2022

Gaming the Christmas Market

Beware of calling long running native code together with high throughput workload in the same JVM

How to build a Docker Image for a SpringBoot Application? | Part-2 | What are Micro-Services?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prabesh Thapa

Prabesh Thapa

DevOps / SRE Engineer. Blog: System admin turned SRE. I love Linux.

More from Medium

How to install Chocolatey in windows- DevOps Champ

Git and GitLab vs Github

How to use Windows Subsystem for LUNIX to Install Ubuntu on your Windows? (Part 2)

Linux: Hard And Soft Links