lina: > On Mon, Jan 30, 2012 at 6:35 PM, Jochen Spieker <m...@well-adjusted.de> wrote: >> lina: >>> >>> I wished at most it only run 8 jobs simultantly, no more than 8, once >>> finished, a new job can continue, >> >> Xargs can be used for this. An exmaple: >> >> $ seq 1 100 | xargs -n1 -P8 echo >> >> Seq prints the numbers from 1 to 100 (one per line) and xargs starts an >> echo for each argument with 8 invocations in parallel. > > I don't get it well.
You could help me helping you by trying to be more verbose about what you don't understand. But anyway, a more detailed explanation: "seq" just prints a sequence of numbers: $ seq 1 3 1 2 3 "xargs" executes the given command (in this example a simple "echo") and adds arguments to this command which it reads from stdin. The --verbose switch makes xargs print the command before it executes it: $ echo 1 | xargs --verbose echo echo 1 1 With more than one line from stdin, xargs adds as many arguments as possible to the command line: $ seq 1 3 | xargs --verbose echo echo 1 2 3 1 2 3 Xargs -n <number> tells xargs to add only <number> of arguments to the command: $ seq 1 3 | xargs --verbose -n1 echo echo 1 1 echo 2 2 echo 3 3 Xargs -P <number> tells xargs to run <number> jobs in parallel, if possible: $ seq 1 3 | xargs --verbose -n1 -P8 echo echo 1 echo 2 echo 3 1 3 2 Of course, since xargs only received three lines of input, it wasn't able to actually run more than three jobs at once. But you can guess that all commands ran more or less in parallel from the fact that the first three lines of output are from xargs and the latter three are from the echo processes that xargs has launched. Incidentally, the three processes didn't even finish in the order they were started. Using two processes in parallel you get something like this: $ seq 1 3 | xargs --verbose -n1 -P2 echo echo 1 echo 2 1 echo 3 2 3 In this example, xargs immediately started another job after the first one finished to keep running two jobs in parallel. J. -- I start many things but I have yet to finish a single one. [Agree] [Disagree] <http://www.slowlydownward.com/NODATA/data_enter2.html>
signature.asc
Description: Digital signature