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
  • 4
    But what can happen is that two copies of sed start reading the file, make different changes, storing them to their respective temporary files, which are then renamed into place one after other, without regard for the fact that there was another sed working on the file at the same time. The changes made by one of the sed processes would be lost. Commented Mar 6, 2019 at 22:05
  • 2
    @ilkkachu that will still be completely consistent -- the file will be either modified by both processes in turn (in any order) or by just one of them. At no point will the file contain garbage resulting from both processes modifying it at the same time. Commented Mar 6, 2019 at 22:15
  • 9
    it won't be total garbage, but having changes lost can still be an issue. The question refers to the file "being locked", and locking would usually refer to the second sed process waiting until the first completed. That might just be awful terminology on their part; it's hard to say what they really care about, but that particular issue is still possible. Commented Mar 6, 2019 at 22:25
  • Good reply, but in my opinion needs a correction, definitely by feature/definition, sed -i on the same file is not thread safe, that would mean handle the concurrency in a reasonable way. When the last one to end "wins", overrides the previous one work, we clearly looking at a race condition, something that should not happen in Thread Safe code. Commented Mar 13, 2024 at 15:11