#!/bin/bash

WAIT=$1
_NRCPU=`getconf _NPROCESSORS_ONLN`
NRCPU=`expr ${_NRCPU} \* 2`

rm -f test_*.log test_*.lock test_*.dat

i=0
while [ $i -lt $NRCPU ]
do
	./test_client.sh $i 2>&1 > test_$i.log &
	let i=$i+1
done

if [ "${WAIT}" = "wait" ]
then
	i=0
	while [ $i -lt $NRCPU ]
	do
		while [ ! -f  test_$i.lock ]
		do
			sleep 1
			uptime
		done
		echo Found test_$i.lock
		let i=$i+1
	done
fi
