[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #38356] xargs -P option creates wrong result

From: Bernhard Voelker
Subject: [bug #38356] xargs -P option creates wrong result
Date: Thu, 21 Feb 2013 14:49:51 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2

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:

  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:


  Message sent via/by Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]