#!/bin/bash
#
# #BINDIR#/runjobsparallel: run all executables in specified directory parallel
# version #VERSION#
#
if [ ! -d "$1" ] || [ $# -ne 1 ]
then
>&2 echo 'runjobsparallel version #VERSION#'
>&2 echo ''
>&2 echo "usage: $0
"
exit 1
fi
cd "$1" || exit 1
tmpDir=$(mktemp -d #TMPDIR#/runjobsparallel.XXXXXX)
for file in ./*; do
if [ -f $file ] && [ -x $file ]; then
i=${#errFiles[@]}
errFiles[${i}]="${tmpDir}/err.${i}"
(nice -n 19 $file; echo $? > ${errFiles[${i}]})&
pids[${i}]=$!
fi
done
allesDa=false
while ! ${allesDa}
do
sleep 1
allesDa=true
maxErr=0
for ((i=0; i<${#errFiles[@]}; i++))
do
ps aux | awk '{print $2}' | grep -q "^${pids[${i}]}\$" && laeuftNoch=true || laeuftNoch=false
if [ -r ${errFiles[${i}]} ]
then
curErr=$(cat "${errFiles[${i}]}")
[ ${curErr} -gt ${maxErr} ] && maxErr=${curErr}
elif ${laeuftNoch}
then
allesDa=false
else
echo 255 > "${errFiles[${i}]}"
maxErr=255
fi
done
done
rm -rf ${tmpDir}
exit ${maxErr}
# End of file