multi process from shell script in parallel in background

Failed test.

1
2
3
4
5
6
7
8
(workspace) ➜ cat test2.sh
#!/bin/bash
for((k=0;k<5;k++));
do sleep 1 &;
done
(workspace) ➜ sh test2.sh
test2.sh: line 3: syntax error near unexpected token `;'
test2.sh: line 3: ` do sleep 1 &;'

Here’s an easy command to fork off a bunch of jobs in parallel.

1
2
3
4
5
6
7
8
9
10
11
(workspace) ➜ cat test1.sh
#!/bin/bash
seq 10 20 | xargs -n 1 -P 5 sleep &
(workspace) ➜ sh test1.sh
(workspace) ➜ ps -eff|grep sleep
501 75381 1 0 9:33下午 ttys001 0:00.00 xargs -n 1 -P 5 sleep
501 75383 75381 0 9:33下午 ttys001 0:00.00 sleep 10
501 75384 75381 0 9:33下午 ttys001 0:00.00 sleep 11
501 75385 75381 0 9:33下午 ttys001 0:00.00 sleep 12
501 75386 75381 0 9:33下午 ttys001 0:00.00 sleep 13
501 75387 75381 0 9:33下午 ttys001 0:00.00 sleep 14