http://blog.chinaunix.net/uid-25324849-id-3077304.html
#! /bin/bash -
set -x
#exec 6<>"mylockfile.sh"
{
flock -n 6
#[ "$?" -eq "1" ] && {echo "fail"; exit;}
if [ "$?" -eq "1" ]; then
echo "fail";
exit;
fi
echo $$
sleep 10
} 6<>"mylockfile.sh"
原文链接:https://www.f2er.com/bash/392113.html