lslocks
Display local system locks information
TLDR
List all local system locks
List locks with defined column headers
List locks producing a raw output (no columns), and without column headers
List locks by PID input
List locks with JSON output to stdout
SYNOPSIS
lslocks [options]
PARAMETERS
-b, --bytes
Display the SIZE column in bytes rather than a human-readable format.
-i, --no-human-readable
A synonym for --bytes.
-J, --json
Use JSON output format.
-l, --list
Use the list output format, where each lock is presented on a separate line.
-n, --noheadings
Do not print a header line in the output.
-o, --output
Specify which output columns to print. Use --help to see a list of all supported columns.
-p, --pid
Display locks held by specific PIDs (comma-separated list of PIDs).
-r, --raw
Use the raw output format, which might be easier for script parsing.
-S, --no-pager
Do not use a pager for the output.
-s, --sort
Sort output by the specified column name.
-t, --truncate
Truncate output when columns are too wide, rather than wrapping.
-u, --no-empty-owner
Do not print locks with an empty owner (e.g., locks from kernel threads).
-V, --version
Display version information and exit.
-h, --help
Display a help message and exit.
DESCRIPTION
lslocks is a command-line utility used to display information about all currently held file locks on the local system. It provides details such as the command holding the lock, the process ID (PID), the lock type, mode (read/write), the number of lock owners, the device and path of the locked file, and the owner of the lock.
This command is particularly useful for diagnosing issues related to file access, such as "Text file busy" errors or unresponsive applications due to resource contention. It primarily focuses on advisory and mandatory locks on local filesystems and usually requires root privileges to view locks not owned by the current user.
CAVEATS
Requires root privileges when listing locks not owned by the current user.
Does not show locks held by network file systems (e.g., NFS).
UNDERSTANDING LOCK TYPES
The TYPE column in lslocks output indicates the locking mechanism used. Common types include FLOCK (advisory locks managed by the flock(2) system call) and POSIX (locks managed by fcntl(2), which can be advisory or mandatory).
INTERPRETING LOCK MODES
The MODE column describes the lock's access type. READ indicates a shared lock, allowing multiple processes to hold a read lock simultaneously. WRITE indicates an exclusive lock, preventing any other process from acquiring any type of lock (read or write) on the same region.
THE BLOCKED/BLOCKER COLUMN
The BLOCKER column displays the PID of the process that is blocking the current lock request, if applicable. Conversely, the BLOCKED column (if enabled via -o) would show the PID of the process being blocked by the current lock.
HISTORY
Part of the util-linux project, lslocks was introduced to provide a dedicated and structured tool for listing file locks. Prior to its existence, this information was often harder to obtain, requiring more generic tools like lsof or fuser combined with manual interpretation. Its development aimed to offer a more direct and detailed insight into the file locking status on a Linux system.