summaryrefslogtreecommitdiff
path: root/runjobsparallel.in
blob: e0a29eb0a5a99a0570c6b90acf19b7dfa874461e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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 <dir>"
  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
    pkill -0 "${pids[${i}]}" \
    && [ ! -r "${errFiles[${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