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

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -