bash - Linux: How to kill Sleep -
more of conceptual question. if write bash script like
control_c() { echo goodbye exit #$ } trap control_c sigint while true sleep 10 #user wants kill process here. done control+c won't exit when sleep 10 running. because linux sleep ignores sigint? there way circumvent , have user able cntrl+c out of sleep?
what describing consistent interrupt signal going bash script, not process group. script gets signal, sleep not, trap cannot execute until after sleep completes. standard trick run sleep in background , wait on it, wait receives interrupt signal. should explicitly send sigint child processes still running, ensure exit.
control_c() { echo goodbye kill -sigint $(jobs -p) exit #$ } trap control_c sigint while true sleep 10 & wait done
Comments
Post a Comment