2 vv_dir=$(dirname $(readlink -e $(which $0)))
3 echo clitk3 directory: $vv_dir
9 rm mem_use 2>>/dev/null
10 killall -s SIGCONT make
13 echo "Terminated, exiting..."
19 trap handle_exit SIGINT
20 available_mem=$(cat /proc/meminfo | grep MemTotal | grep -o [0-9]*)
21 if [ -a "memory_exhausted_lock" ]
23 echo "Running in memory conservation mode..."
24 max_cpp_process_mem_use=1600000
25 cpus=$(( $available_mem / $max_cpp_process_mem_use ))
26 echo "Using $cpus cpu(s) should be safe..."
29 else #use all the available computing power by default
30 cpus=$(( $(cat /proc/cpuinfo | grep -c ^processor) + 0 ))
31 echo "Building with ${cpus} cpus..."
34 nice -n12 ionice -c3 make -j ${cpus} $@ &
35 make_pid=$(jobs -p %nice)
37 #watch memory use to avoid crashes
38 #while ps $make_pid >>/dev/null
40 # if [ x"$(ps aux | grep cc1plus | grep -v grep | wc -l)" != x0 ]
42 # ps ax -o vsize,comm | grep cc1plus | grep -o "\<[0-9]*\>" > mem_use
43 # used_mem=$(awk 'BEGIN {sum=0;} {sum+=$1;} END {print sum;}' mem_use)
44 # if (( "$used_mem"> ($available_mem - 300) ))
46 # touch memory_exhausted_lock
47 # echo "Stopping due to exagerated memory use ( $used_mem )"
49 # elif (( "$used_mem"> ($available_mem/2) ))
51 # if [ x$high_mem != xtrue ]
53 # echo "Warning, high memory use, not spawning any more compilation jobs... ( $used_mem )"
54 # killall -s SIGSTOP make
55 # killall -s SIGCONT cc1plus
57 # date_mem=$(date +%s)
59 # echo mem $used_mem / $available_mem
60 # elif [ x$high_mem = xtrue ] && (( $(date +%s) > ( $date_mem + 5 ) ))
62 # echo "Memory use back to normal"
64 # killall -s SIGCONT make
70 #rm memory_exhausted_lock 2>>/dev/null