Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

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

📅 2013-Jan-19 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ file, lock, lsof, ubuntu ⬩ 📚 Archive

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

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧