Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out what process has a lock on a file in Linux?

Today I had the problem that I couldn't delete a folder because "it was busy".

How can I find out which application to blame for that or can I just delete it with brute force?

like image 372
Xn0vv3r Avatar asked Jan 13 '09 14:01

Xn0vv3r


People also ask

How do you check which process is locking a file Linux?

lsof can help to see the list of file. here is way to see the locked files. Show activity on this post. in case lsof itself is missing on the system, ls /proc/*/fd/* | grep LOCK_FILE_NAME should provide the same information.

Where is lock file in Linux?

Lock files should be stored within the /var/lock directory structure. Lock files for devices and other resources shared by multiple applications, such as the serial device lock files that were originally found in either /usr/spool/locks or /usr/spool/uucp , must now be stored in /var/lock .

Why is a file locked in Linux?

File locking is a mechanism to restrict access to a file among multiple processes. It allows only one process to access the file in a specific time, thus avoiding the interceding update problem.


1 Answers

lslocks lists information about all the currently held file locks in a Linux system. (part of util-linux) this utility has support for json output, which is nice for scripts.

~$ sudo lslocks
COMMAND           PID   TYPE SIZE MODE  M START END PATH
cron              873  FLOCK   4B WRITE 0     0   0 /run/crond.pid

..
..

like image 53
Chen A. Avatar answered Sep 28 '22 07:09

Chen A.