http://blog.bsdhack.org/index.cgi/Computer/20120621.html
# Check single run start # http://blog.bsdhack.org/index.cgi/Computer/20120621.html lockfile=${TMP:-/tmp}/${0##*/} while true do if ln -s $$ ${lockfile} 2> /dev/null then break else if [ -d /proc/`ls -l ${lockfile} | sed 's!.* !!g'` ] then echo "${0##*/}: exist another instance" 1>&2 exit 1 else rm -f ${lockfile} fi fi done # Check single run end trap 'rm -f ${lockfile}; exit' 0 1 2 3 11 15
めも、詳細未検証