Commit 89bbe630 authored by David Gauchard's avatar David Gauchard
Browse files

initial commit

parents
#!/bin/bash
time_limit=3600s
set -e
help ()
{
cat << EOF
Syntax: $1 [-t timelimit]
Start local executables concurrently,
limited by the number of cores reported by 'nproc' ($(nproc) on this host).
Options:
-t timelimit (default: ${time_limit})
EOF
exit 1
}
while [ ! -z "$1" ]; do
case "$1" in
-t) time_limit="$2"; shift;;
-h) help "$0";;
*) echo "argument $1 not understood"; help "$0"; exit 1;;
esac
shift
done
ncpu=$(nproc)
pids=.pid
mkdir -p ${pids}
rm -f ${pids}/*
for exec in *; do
# must be executable
[ -x ${exec} ] || continue
# log file must not already exist
[ -r ${exec}-log.txt ] && { echo "${exec}: logfile already exists"; continue; }
while true; do
ucpu=$(ls ${pids} | wc -l)
if [ ${ucpu} = ${ncpu} ]; then
echo "(all cpu used)"
sleep 1
else
echo "start '${exec}'"
( set +e; \time timeout ${time_limit} ./${exec} >& ${exec}-log.txt & pid=$!; echo ${exec} > ${pids}/${pid}; wait ${pid}; rm -f ${pids}/${pid}; ) &
break
fi
done
done
echo ""
echo "all started"
while true; do
ucpu=$(ls ${pids} | wc -l)
if [ ${ucpu} = 0 ]; then
echo "all finished"
break
fi
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment