FLOCK(1) FLOCK(1) (NAME) flock - (SYNOPSIS) flock [options] file|directory command [arguments] flock [options] file|directory -c command flock [options] number (DESCRIPTION) flock(2) . command su(1) newgrp(1). file directory ( ) . flock . number (file descriptor) . . (OPTIONS) -c, --command command command -c. -E, --conflict-exit-code number -n -w . 1 . number 0 255 . -F, --no-fork command (fork) . flock command . --close . -e, -x, --exclusive . . -n, --nb, --nonblock . -E . -o, --close command. command . -s, --shared . -u, --unlock . . . -w, --wait, --timeout seconds seconds . . -E . seconds --nonblock . --fcntl flock(2) fcntl(2) ( F_OFD_SETLK () F_OFD_SETLKW ()). flock(2) POSIX fcntl() ( F_SETLK F_SETLKW) flock(2) . >= 3.15 . --verbose . -h, --help . -V, --version . (EXIT STATUS) -n -w -E 1 . -E 0 255 . command . (NOTES) flock (deadlock) . flock(2) . ( NFS CIFS) flock(2) flock . flock(2) nfs(5) mount.cifs(8) . mount flock . (EXAMPLES) "shell> " . shell1> flock /tmp -c cat; shell2> flock -w .007 /tmp -c echo; /bin/echo $? /tmp . shell1> flock -s /tmp -c cat; shell2> flock -s -w .007 /tmp -c echo; /bin/echo $? /tmp . . shell> flock -x local-lock-file echo 'a b c' "local-lock-file" echo 'a b c'. (; flock -n 9 || exit 1; # ... commands executed under lock ...; ) 9>/var/lock/mylockfile . flock > >> . < . [ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || : . . $FLOCKER flock ( ) . FLOCKER . shell> exec 4<>/var/lock/mylockfile; shell> flock -n 4 . 4 flock . (AUTHORS) H. Peter Anvin (COPYRIGHT) Copyright (C) 2003-2006 H. Peter Anvin. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. (SEE ALSO) flock(2), fcntl(2) (REPORTING BUGS) . (AVAILABILITY) flock util-linux . util-linux 2.41.5 2026-06-16 FLOCK(1)