{
    "mode": "perldoc",
    "parameter": "flock",
    "section": "-f",
    "url": "https://www.chedong.com/phpMan.php/perldoc/flock/json",
    "generated": "2026-06-03T04:23:57Z",
    "sections": [],
    "flags": [],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Manage file locks from shell scripts.",
        "examples": [
            {
                "description": "Run a command with a file lock as soon as the lock is available",
                "command": "flock {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Run a command with a file lock, or exit if the lock is currently being held (with exit code 1)",
                "command": "flock {{-n|--nonblock}} {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Run a command with a file lock, or exit with a specific error code if the lock is currently being held",
                "command": "flock {{-n|--nonblock}} {{-E|--conflict-exit-code}} {{123}} {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Run a command with a file lock, waiting up to 10 seconds for the lock to be available before giving up",
                "command": "flock {{-w|--timeout}} 10 {{path/to/lock.lock}} {{command}}"
            },
            {
                "description": "Backup a bunch of files, waiting for the previous `tar` command to finish if it's still running elsewhere and holding the same lock file (can be used in a `cron` job that runs often)",
                "command": "flock {{path/to/backup.lock}} {{tar -cvf path/to/backup.tar path/to/data/}}"
            }
        ]
    }
}