I am looking at the flock docs:
http://www.tutorialspoint.com/unix_system_calls/flock.htm
https://linux.die.net/man/1/flock
I have this:
#!/usr/bin/env bash
temp_dir="$HOME/temperton/tmp";
mkdir -p "$temp_dir"
(
flock -x "$temp_dir/a"
echo '111'
) &
(
flock -x "$temp_dir/a"
echo '222'
) &
but when I run it I get this error:
flock: bad file descriptor: '/home/ratt/temperton/tmp/a' flock: 111 bad file descriptor: '/home/ratt/temperton/tmp/a' 222