H4XPK
08-03-2007, 03:32 PM
Problem with script below is (as you can see after running it) that it will "MISS" processess. I named this script as "test". Look at the results:
./test
a - 1
b - 2
c - 3
d - 4
f - 6
g - 7
i - 9
h - 8
k - 11
As you can see, where is number 5,8 and 10 !? More threads i use, less it will miss but this is absolutely no solution. Does anyone have any idea howto fix
this issue or howto make it catch numbers it "MISSED" ?
I have tried both latest Zsh/Bash, same problem. Is this bug in both shells or is my code buggy (i cant find any though).
Code:
#!/bin/sh
PROCID=1
THREADS=5
X=1
for Z in a b c d e f g h i j k l m n o p q s t ; do
function Module () {
A=$1
echo "$Z - $A" && sleep 0.5
}
if [ ! "$PROCID" -eq "$THREADS" ] ; then
Module $X &
let "PROCID++"
else
wait
PROCID=1
fi
X=$(( X+1 ))
done
wait
./test
a - 1
b - 2
c - 3
d - 4
f - 6
g - 7
i - 9
h - 8
k - 11
As you can see, where is number 5,8 and 10 !? More threads i use, less it will miss but this is absolutely no solution. Does anyone have any idea howto fix
this issue or howto make it catch numbers it "MISSED" ?
I have tried both latest Zsh/Bash, same problem. Is this bug in both shells or is my code buggy (i cant find any though).
Code:
#!/bin/sh
PROCID=1
THREADS=5
X=1
for Z in a b c d e f g h i j k l m n o p q s t ; do
function Module () {
A=$1
echo "$Z - $A" && sleep 0.5
}
if [ ! "$PROCID" -eq "$THREADS" ] ; then
Module $X &
let "PROCID++"
else
wait
PROCID=1
fi
X=$(( X+1 ))
done
wait