The lslk(8) program has been unmaintained and deprecated for over a decade now, since 2001. I've recently rewritten the tool, now called lslocks(8) that allows an easier and up-to-date way of seeing all the current file held locks in a Linux system. This program will be shipping soon with standard system tools and available in your favorite distribution.
Some important modifications include removing legacy Unix outputs and options, for example:
- Don't output inode number, whence and maj:min device numbers.
- Don't provide nonblocking syscall options stat(2) and readlink(2).
- The option to use nonblocking calls was previously intended for NFS partitions; however this should be transparent to utility programs considering that timeouts can occur generically in any context (fuse - sshfs, NFS, netdevs, etc).
The command itself is quite straightforward - KISS:
$> lslocks
COMMAND PID TYPE SIZE MODE M START END PATH
smbd 1379 POSIX 5B WRITE 0 0 0 /var/run/samba/smbd.pid
smbd 1379 POSIX 696B READ 0 4 4 /var/run/samba/messages.tdb
...
smbd 1379 POSIX 696B READ 0 4 4 /var/run/samba/gencache_notrans.tdb
smbd 1513 POSIX 696B READ 0 4 4 /var/run/samba/messages.tdb
(unknown) 1717 FLOCK 0B WRITE 0 0 0 /var/run
atd 1793 POSIX 5B WRITE 0 0 0 /var/run/atd.pid
sendmail-mta 2004 POSIX 52B WRITE 0 0 0 /var/run/sendmail/mta/sendmail.pid
nmbd 2292 POSIX 5B WRITE 0 0 0 /var/run/samba/nmbd.pid
nmbd 2292 POSIX 696B READ 0 4 4 /var/run/samba/messages.tdb
nmbd 2292 POSIX 108K READ 0 4 4 /var/run/samba/connections.tdb
cat 3221 POSIX 0B WRITE 0 0 0 /home/dave/.local/share/zeitgeist/fts.index/flintlock
zeitgeist-daemo 3211 POSIX 989K WRITE 0 1073741824 1073742335 /home/dave/.local/share/zeitgeist/activity.sqlite
chromium-browse 4306 POSIX 202K WRITE 0 1073741824 1073742335 /home/dave/.config/chromium/Default/Web Data
...
We can quickly see the command name and PID that currently cause a lock to be held, as well as its size and canonical path. The lock itself, can be FLOCK (created with flock(2)) or POSIX (created with fcntl(2) and lockf(2)) - I won't go over explaining the differences as it's not in the context of this post. The start and end are the relative byte offset of the lock.
Enjoy!
💬 Debate de la comunidad y comentarios
Inicia el debate en el stream de difusión del Social Chat o envía arriba una contribución experta mediante el formulario de ampliación.