How to check if a file is locked in Linux?
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: