$ cd ../
locks-watch — bash

user@devops:~$ cat README.md

locks-watch

# Description

locks-watch (cpp-locks-watch) is a Linux kernel file-lock monitor written in C++23 with zero external dependencies. It reads /proc/locks and shows every lock on the system: type FLOCK (flock(2)), POSIX (fcntl F_SETLK/F_SETLKW) or OFDLCK (open file description locks); mode ADVISORY or MANDATORY (mandatory locks, only with mand mounts + setgid without group-execute); READ or WRITE access; owner PID resolved to a process name via /proc/<pid>/comm; MAJ:MIN device and file inode; and the locked byte range (0-EOF whole file, single offset like 128, or finite range like 1024-2048). The internal sentinel uses end=-1 for EOF so an explicit "0 0" still means a single-byte lock. Filters --type FLOCK|POSIX|OFDLCK, --access READ|WRITE, --mandatory, --pid N, --top N and --sort id|pid|inode. --byte-range keeps only finite ranges. Watch mode (--watch N) prints deltas of new/released locks between snapshots. JSON output (--json) with summary + locks array validatable with python -m json.tool. --demo with 32 locks of a synthetic DB + web + browser host and --file for dumps that tolerate # comments. Selftest 42 checks: parser, EOF vs single byte, filters, demo, JSON and real /proc reads. Zero deps: g++ -std=c++23 -O2 -Wall -Wextra.

# Key features

$ Reads /proc/locks: FLOCK, POSIX and OFDLCK with ADVISORY/MANDATORY mode

$ Byte ranges: 0-EOF whole file, single offset or finite range (--byte-range)

$ PID -> process resolution via /proc/<pid>/comm, tolerant to dead processes

$ Watch mode (--watch N) with new/released lock deltas between snapshots

$ Filters --type, --access, --mandatory, --pid, --top and --sort id|pid|inode

$ Validatable JSON output with summary + locks array; --demo with 32 synthetic locks

$ --file parses dumps with # comments; --no-color with mutable ANSI palette (0 escapes)

# Gallery

Project terminal
locks-watch - Project terminal
Mobile view
locks-watch - Mobile view

# Technologies used

C++23