Sunday, February 24, 2013

/proc/locks


/proc/locks file displays the files currently locked by the kernel. This file has 8 fields.

$ cat /proc/locks
1: POSIX  ADVISORY  WRITE 229903 fd:132:639017 0 EOF
2: POSIX  ADVISORY  WRITE 555736 fd:132:1016088 0 EOF
3: FLOCK  ADVISORY  WRITE 522736 fd:132:1016016 0 EOF
4: FLOCK  ADVISORY  WRITE 522700 fd:132:1015984 0 EOF
5: POSIX  ADVISORY  WRITE 520967 fd:132:1015829 0 EOF
6: POSIX  ADVISORY  WRITE 463519 fd:00:2523477 0 EOF
7: POSIX  ADVISORY  WRITE 47253 fd:00:2523816 0 EOF
8: FLOCK  ADVISORY  WRITE 47223 fd:00:2523810 0 EOF
9: FLOCK  ADVISORY  WRITE 47202 fd:00:2523424 0 EOF
10: POSIX  ADVISORY  WRITE 10573 fd:00:2523558 0 EOF
11: POSIX  ADVISORY  WRITE 10566 fd:00:2523507 0 EOF

Column 1 : Each lock has its own line which starts with a unique number
Column 2 : This column refers to the class of lock used, with FLOCK signifying the older-style UNIX file locks from a flock system call and POSIX representing the newer POSIX locks from the lockf system call.
Column 3 : This has two values  ADVISORY or MANDATORY. ADVISORY means that the lock does not prevent other people from accessing the data; it only prevents other attempts to lock it. MANDATORY means that no other access to the data is permitted while the lock is held.
Column 4 : This reveals whether the lock is allowing the holder READ or WRITE access to the file
Column 5 : This shows the ID of the process holding the lock.
Column 6 : This column shows the ID of the file being locked, in the format of MAJOR-DEVICE:MINOR-DEVICE:INODE-NUMBER.
Column 7, 8 : The last two columns show the start and end of the file's locked region.

How to enable MANDATORY locking on a file?

To enable MANDATORY locking on a file enable the SGID bit for the file but disable the group execute bit, like follows

# chmod g+s-x /path/to/file

No comments:

Post a Comment