Skip to main content
1 of 2
Petr Skocik
  • 29.7k
  • 18
  • 90
  • 154

Yes, it is. Exec just replaces the process image, but it's still the same process so the OS-level locks associated with it remain the same.

It's very easy to verify that it works:

lock

(
    flock -n 200 || exit 1;
    echo "locked"
    exec ./script
) 200>program.lock

script

sleep 100

Try running ./lock twice within then next 100 seconds. You'll only get the lock once, ergo exec doesn't release the lock.

Petr Skocik
  • 29.7k
  • 18
  • 90
  • 154