Mac OS X equivalent of Linux flock(1) command
问题 Is there a flock command on Mac OS X that manages file lock? http://linux.die.net/man/1/flock 回答1: There is a cross-platform flock command here: https://github.com/discoteq/flock I have tested it and it works well on OSX as a drop-in replacement for the util-linux flock. 回答2: Perl one-liner: perl -MFcntl=:flock -e '$|=1; $f=shift; print("starting\n"); open(FH,$f) || die($!); flock(FH,LOCK_EX); print("got lock\n"); system(join(" ",@ARGV)); print("unlocking\n"); flock(FH,LOCK_UN); ' /tmp