#! /bin/sh # # bad lock using touch and file, not atomic proc() { echo "Process $1 begin" if [ -r lockfile ]; then # lock already exists echo "Process $1 can't lock" else # lock did not exist, but another process could get it ahead of us touch lockfile # get the lock echo "Process $1 got lock" fi echo "Process $1 end" } rm -f lockfile proc 1 & proc 2 & proc 3 & wait rm -f lockfile