Skip to main content
added 1 character in body
Source Link
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'tdoes not release the lock.

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.

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 does not release the lock.

Source Link
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.