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*

4
  • 1
    The way I read your example you locked a file called sed in the current directory .... not sure what the rest of the command will do. Commented Mar 13, 2024 at 17:28
  • Hello, typing back here I missed typing the first argument of flock in the example. That was not what I implemented in my situations with a concrete sed -i (of an application level data corruption issue). Fixed my reply. Hope now it is correct and useful for similar situations. Thanks for the feedback. Commented Mar 14, 2024 at 6:02
  • 1
    Would it not potentially be problematic to use flock with the same file you use with sed? It more common to use flock with a separate file. After all, you are not locking the file, you are locking the operation. Also, your code needs double quoting of all shell variable expansions. Commented Mar 14, 2024 at 11:28
  • Thanks, that is just example, not real code. Flock is all about controlling access to shared resources, same file. The sed on the same file is the not so great practice. In my specific case working on adding gnu parallel on existing large shell script code base. Using flock to control the concurrent access on operation worked great. Commented Mar 15, 2024 at 13:09