0

I have many scripts shell that are executing at the same time and they make sed on the same file. So there is a risk that the sed command exeute at the same time and on the same file.

Should I make a race condition check on a parallel sed executions on the same file?

MOHAMED
  • 41,599
  • 58
  • 163
  • 268
  • 3
    Do you mean inplace-editing or just using the same file as input for several concurrent sed commands? – Wintermute Mar 02 '15 at 11:08
  • depend also of the sed action. If it add info for example, independantly of other lines (or if not found) could use parallele without lock. In fact it will mainly depend on wanted modification that is very wide as possibility – NeronLeVelu Mar 02 '15 at 13:00
  • @Wintermute The `sed` commands are editing the file with `-i` ==> removing lines – MOHAMED Mar 02 '15 at 14:08

1 Answers1

1

It depends. Are some of these executions of sed editing the file (eg with the -i option of gnu-sed) and do you expect consistent, reliable output? If so, then yes, you need a lock. Be aware that sed -i does not modify the file you are working on; it creates a temporary file and renames it, and this will affect your analysis of the race condition. If none of your scripts are modifying the file then there is no race condition and no need for a lock.

William Pursell
  • 204,365
  • 48
  • 270
  • 300