太帥了,不得不轉載。
[root@H209 tmp]# seq 10 20 | xargs -n 1 -P 5 sleep
按ctrl+z
[1]+ Stopped seq 10 20 | xargs -n 1 -P 5 sleep
[root@H209 tmp]# bg
[1]+ seq 10 20 | xargs -n 1 -P 5 sleep &
[root@H209 tmp]#
[root@H209 tmp]# ps aux|grep sleep
root 7327 0.0 0.0 4312 508 pts/1 S 13:56 0:00 xargs -n 1 -P 5 sleep
root 7328 0.0 0.0 4052 476 pts/1 S 13:56 0:00 sleep 10
root 7329 0.0 0.0 4052 476 pts/1 S 13:56 0:00 sleep 11
root 7330 0.0 0.0 4052 472 pts/1 S 13:56 0:00 sleep 12
root 7331 0.0 0.0 4052 476 pts/1 S 13:56 0:00 sleep 13
root 7332 0.0 0.0 4052 476 pts/1 S 13:56 0:00 sleep 14
root 7334 0.0 0.0 4392 696 pts/1 S+ 13:56 0:00 grep sleep
-n的意思是每次使用幾個參數:
--max-args=max-args, -n max-args
Use at most max-args arguments per command line.
-P(大寫)的意思是並發的進程數量:
--max-procs=max-procs, -P max-procs
Run up to max-procs processes at a time; the default is 1.
If max-procs is 0, xargs will run as many processes as possible at a time.
Use the -n option with -P;
otherwise chances are that only one exec will be done.