Xn0vv3r
Xn0vv3r

Reputation: 18184

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?

Upvotes: 14

Views: 54991

Answers (4)

Chen A.
Chen A.

Reputation: 11338

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

..
..

Upvotes: 8

Bombe
Bombe

Reputation: 83943

fuser will show you which processes are accessing a file or directory.

Upvotes: 3

dF.
dF.

Reputation: 75845

The fuser Unix command will give you the PIDs of the processes accessing a file.

Upvotes: 13

tddmonkey
tddmonkey

Reputation: 21184

Use lsof to find out what has what files are open.

man lsof or have a look here

Upvotes: 12

Related Questions