1#!/system/bin/sh 2# Usage: spin_n_threads.sh <num_threads> [<nice>] 3# spin_n_threads.sh kill 4 5TGID_FILE=/data/local/tmp/spin_n_threads_tgid.txt 6 7spin_loop() { 8 while : 9 do 10 NUM=$(expr 1 + 1) 11 done 12} 13 14clean_up() { 15 trap - SIGINT SIGTERM SIGKILL 16 kill -- -$$ 17} 18 19NUM_THREADS=1 20if [ ! -z ${1} ]; then 21 if [ ${1} == "kill" ]; then 22 TGID=$(cat ${TGID_FILE}) 23 kill -- -${TGID} 24 exit 0 25 fi 26 27 if [ ${1} -gt 1 ]; then 28 NUM_THREADS=${1} 29 else 30 exit 0 31 fi 32fi 33 34if [ ! -z ${2} ]; then 35 renice -n ${2} -p $$ 36fi 37 38# Register cleanup on trap 39trap clean_up SIGINT SIGTERM SIGKILL 40for i in $(seq 1 $NUM_THREADS ); do 41 spin_loop & 42done 43 44echo $$ > ${TGID_FILE} 45