Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    Yes, I use this technique a lot. The advantage of using a subshell and locking the file descriptor is that my script doesn't have to explicitly unlock the lockfile. When the subshell exits, the unlock is automatic. Commented Oct 25, 2022 at 10:08
  • This is pretty much what I need, but I am wondering is there any workaround on SIGTSTP (e.g. if user does CTRL+Z in the shell before finishing the 10seconds and then re-tries this, the lock is still there, so unless removing it manually it will not allow him to execute). Commented Oct 25, 2022 at 10:26
  • @classicmusiclover well, yes. If you don't allow the program to end then it hasn't ended. SIGTSTP is catchable, if you are really concerned about this possibility Commented Oct 25, 2022 at 10:29
  • Why wouldn't it work with NFS? NFS does have a lock manager (NLM). Commented Oct 25, 2022 at 11:29
  • @aviro depending on which set of documentation you read, and which OS you're running, flock may or may not work over NFS. Note that the question doesn't specifically reference Linux. Commented Oct 25, 2022 at 12:18