# `set -C` must not clobber, must allow a device, and its test and # creation must be one step so the lock idiom has exactly one winner. "$TSH" -c 'set -C; : >/dev/null; echo "null $?"' # Keep the second case out of the shell that would exit on the bad redirect. "$TSH" -c 'set -C; : >f; echo "new $?"' "$TSH" -c 'set -C; : >f; : >f' 2>/dev/null echo "again $?" cleared=0 for _ in 1 2 3 4 5 6 7 8; do rm -f lock ("$TSH" -c 'set -C; echo a >lock' 2>/dev/null; echo $? >s1) & ("$TSH" -c 'set -C; echo b >lock' 2>/dev/null; echo $? >s2) & wait [ "$(cat s1)" = 0 ] && cleared=$((cleared + 1)) [ "$(cat s2)" = 0 ] && cleared=$((cleared + 1)) done echo "created $cleared of 8"