run_GIGI 1.3 KB
Newer Older
1 2
#!/bin/bash

3
#set -x
4

5 6 7 8 9 10 11 12 13 14 15 16
export waiting=false
function finish {
  echo "SIGINT caught!"
  if [ "$waiting" = true ]
  then
    echo "Attempting to kill unfinished GIGI threads..."
    # kill straggling threads
    #timeout --preserve-status 5 killall --wait -i GIGI
    #if [ $? -ne 0 ]
    #then
    #  timeout --preserve-status 5 killall --wait -i -s SIGKILL GIGI
    #fi
17 18 19 20 21 22 23 24 25 26
    #Check exit status
    for pid in ${pids[*]}
    do
      id=$(pgrep -P ${pid})
      echo "${id}"
      kill "${id}"
      echo "gigi pid: ""${pid}" " has been killed by ctrl+c/SIGINT"
    done
    waiting=false
    #killall --wait GIGI
27 28 29 30 31 32 33 34 35 36 37
  fi
  #echo "Killing self with SIGINT"
  kill -INT $$
  #echo "Killing self"
  #timeout 5 kill $$
  #echo "Hard killing self."
  #timeout 5 kill -9 $$
}
#trap finish EXIT
trap 'finish; trap - SIGINT; kill -INT $$' SIGINT
#trap finish SIGTERM
38

39 40 41
export base_path=$(pwd)
export parent_path=$( cd "$(dirname $(readlink -f "${BASH_SOURCE[0]}"))" ; pwd -P )
echo "Parent Path: " "${parent_path}"
42 43 44 45 46 47 48 49 50 51 52
cd "$parent_path"

if [ -p /dev/stdin ]
then
  . ./GIGI_0_parsing.sh $(cat "$@")
else
  if [ "${@:1:1}" ]
  then
    . ./GIGI_0_parsing.sh "$@"
  else
    echo "NO ARGUMENTS GIVEN"
53
    echo "Usage: run_GIGI parameter_file -o [OUTPUT FOLDER] -n [RUN NAME] -t [THREADS] -m [MEMORY IN MB] [-l] [-v] [-V] [-h]"
54 55 56
    exit 1
  fi
fi