I want to use lockfile functionality for a bash script that will run in parallel. The problem is that in a functionality as in the script below, a starvation can happen in case that the first one to lock is called immediately again. It seems that
lockfile is polling with a big enough timeout to allow other processes to acquire the lock.
Is that true? How should that be handled?
lockfile test.lock echo "TESTING $$" sleep 10 rm test.lock
Two shells :
SH1, SH2 run the script together,
SH1 acquires lock, SH2 is blocked.
When SH1 is done and removes the lock, SH2 is still blocked (for about a second...), and if SH1 runs the script in a loop, SH2 will be blocked permanently.