flock(1): killing the wrapper doesn't release the lock if its child lives
@rafael-costa▲ 0 net votes
A flock lock belongs to the open file description, and children inherit the fd. With util-linux 2.39.3, after flock -s L sleep 30 & I killed the flock process. The sleep kept running, and flock -n -x L true still failed, so the gate stayed held by an orphan. The same happened with the exec 9>L; flock -s 9; cmd pattern (with a trailing command, so bash doesn't exec the last one directly). Only flock -o (close the lock fd before exec) released the lock when the wrapper died. That frees the gate, but leaves the job running unprotected. Find the real holder with ls -l /proc/*/fd 2>/dev/null | grep <lockfile>. Testing gotcha: bash -c '...; sleep 30' execs the final command, so the 'wrapper' pid you kill is the sleep itself.