3 temp=$(readlink -e "${temp}")
4 vv_dir=$(dirname "${temp}")
5 echo clitk3 directory: $vv_dir
11 rm mem_use 2>>/dev/null
12 #kill -s SIGCONT ${make_pid} $(get_descendance ${make_pid})
14 kill -9 $(get_descendance ${make_pid})
16 echo "Terminated, exiting..."
23 function get_descendance
25 children=$(ps --ppid $1 -o pid --no-headers)
29 desc="${desc} ${c} $(get_descendance $c)"
34 trap handle_exit SIGINT
35 available_mem=$(cat /proc/meminfo | grep MemTotal | grep -o [0-9]*)
36 if [ -a "memory_exhausted_lock" ]
38 echo "Running in memory conservation mode..."
39 max_cpp_process_mem_use=1600000
40 cpus=$(( $available_mem / $max_cpp_process_mem_use ))
41 echo "Using $cpus cpu(s) should be safe..."
44 else #use all the available computing power by default
45 cpus=$(( $(cat /proc/cpuinfo | grep -c ^processor) + 0 ))
46 echo "Building with ${cpus} cpus..."
49 nice -n12 ionice -c3 make -j ${cpus} $@ &
50 make_pid=$(jobs -p %nice)
52 #watch memory use to avoid crashes
53 while ps $make_pid >>/dev/null
55 descendance=$(get_descendance ${make_pid})
56 #echo ${make_pid} $descendance
57 ps -o vsize --no-headers ${make_pid} ${descendance} > mem_use
58 used_mem=$(awk 'BEGIN {sum=0;} {sum+=$1;} END {print sum;}' mem_use)
59 if (( "$used_mem"> ($available_mem - 300) ))
61 touch memory_exhausted_lock
62 echo "Stopping due to exagerated memory use ( $used_mem )"
64 elif (( "$used_mem"> ($available_mem/2) ))
66 if [ x$high_mem != xtrue ]
68 echo "Warning, high memory use, not spawning any more compilation jobs... ( $used_mem )"
69 #Stop all make commands
70 for pid in ${make_pid} ${descendance}
72 (ps --no-headers -o command ${pid} | grep make &>/dev/null) && kill -s SIGSTOP ${pid}
77 echo mem $used_mem / $available_mem
78 elif [ x$high_mem = xtrue ] && (( $(date +%s) > ( $date_mem + 5 ) ))
80 echo "Memory use back to normal"
82 #Restart all make commands
83 for pid in ${make_pid} ${descendance}
85 (ps --no-headers -o command ${pid} | grep make &>/dev/null) && kill -s SIGCONT ${pid}
91 rm memory_exhausted_lock 2>>/dev/null
92 echo Waiting for remaining jobs...