Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Mar 022010
 

How to check if a file is locked in Linux?

Answer:

Suppose a file test.txt is being locked by a program, e.g. using the flock system call, how can we know if this file is really being locked?

# lsof test.txt
COMMAND  PID USER   FD   TYPE DEVICE SIZE   NODE NAME
perl    5654 john 3uW  REG    8,1    1 983057 test.txt

The W means the file is currently held by an exclusive lock. You can find more information in the link below:

http://linux.die.net/man/2/flock