My script runs a loop for each one of the parameters passed:
for ((i=1; i<=$TEST_AMOUNT; i++))
do
trap '{.... ;}' INT
TEST_NAME=${!i}
run.sh $TEST_NAME false $MULTIPLE_TESTS | tee -ai testing.out
done
If the trap catches an interrupt signal, I need to move the whole loop to the background and run it in nohup. I was thinking something like nohup pid &
. What is the best way to do this?
答案 0 :(得分:0)
What you seem to want is not really possible, but you can certainly do:
do
trap INT # ignore SIGINT
nohup run.sh $TEST_NAME false $MULTIPLE_TESTS | tee -ai testing.out &
wait
done
which has the same effect. (If I understand what you want, which is not entirely clear.)
When you run the process in the foreground, a SIGINT that is generated from the keyboard is not going to be seen by your script until the run.sh script gets it and terminates. If run.sh ignores the signal, or handles it and does not terminate, your trap will not execute. In other words, under no circumstances will your trap execute until run.sh
has terminated.