I have a script which locks a file to avoid concurrent access to it, How can I execute this same script from two different terminals synchronously, to check if it works?
Here is the script
#!/bin/bash
(
flock -xn 200
trap 'rm /tmp/test_lock.txt' 0
RETVAL=$?
if [ $RETVAL -eq 1 ]
then
echo $RETVAL
echo "file already removed"
exit 1
else
echo "locked and removed"
fi
) 200>/tmp/test_lock.txt
$?
in your code expands to the exit status oftrap
. I guess this is not what you want.