How to find the process that has locked a file or directory in Ubuntu

When you open a program in Ubuntu, it might quit complaining that another process has locked a file or directory it is trying to open.

For example, here is an error of this kind:

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

To continue, you might have to find the offending process and stop it. The lsof command can be used for this purpose.

For example, to find out which process has locked the /var/lib/dpkg directory in the above example:

 $ lsof | grep /var/lib/dpkg
 

Tried with: Ubuntu 12.04.1 LTS

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s