Follow-up Comment #2, bug #38356 (project findutils):

The problem is that all parallel instances of grep have the
output file open for writing at the same time, and they do
not care about locking it. Therefore, I do not consider this
an xargs bug as xargs can nothing do about it.

Instead, you could synchronize writing of grep's output by an
intermediate wrapper script which obtains an exclusive lock on
stdout before writing the result:

  #!/bin/sh
  matches=$( grep "$@" )
  flock 1
  printf "%sn" "$matches"

Please note that you could also flock stdout before grep to
avoid the intermediate 'matches' variable, but this would
obvisouly lock out all other parallel grep processes until
this one has finished.
For larger program output, you may need to use a temporary
file instead of 'matches'.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?38356>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/


Reply via email to