The full title of this question is:
Bash: What to do when control-c won't kill a process, due to the fact that the bash script contains a loop which calls another process: Is there a better solution to the on/off power button?
The title of this question is fairly self explanatory, but here's some more detailed information:
I have a bash script running which calls another program. (Runs / executes another program.)
This program is a data/curve fitting program, which cannot be interrupted with
CTRL-C. But, from reading this post, I found I can kill it with
So it is possible to just mash the keyboard, holding CTRL down, and mashing the
\ key, BUT what if you bought a really expensive mechanical keyboard yesterday and don't have enough money to buy another cheap keyboard you're willing to "mash" (because you don't want to use up any of those 10^6 key-presses you have before your shiny new mechanical keyboard will wear out), or alternatively don't have enough time to find your old keyboard in your house because your house is either extremely disordered (a mess) or because there is an emergency such as a chip-pan fire occurring simultaneously...
Also consider that a loop is calling this fitting program and perhaps you're fitting 1000 data files, pressing the
\ key 1000 times is likely to take a long time.
Or even; what if you made a mistake in the bash script and it's actually executing an infinite loop?
What can you do to stop the parent script running in this situation? You could unplug your computer, hold the power button down for 10 seconds to turn it off, or throw it into the chip-pan fire to stop it working, but these solutions seem insensible due to the possible loss of data which may occur.
In theory, one could run the system monitor and perhaps quit the bash process, but this may be difficult to find if you have many such processes all with the same name... In addition, you might have a single core computer, or a multicore computer with say N cores, running N processes which are all trying to use 100 % CPU. Or perhaps just 1 process is using more than the 4 GB of ram you have and so your computer is extremely slow for that reason... Too slow at least to run the system monitor for now. The next best option after this is to press CTRL-ALT-F1 and try to log in as root and find the offending bash parent using
ps -A then
kill PID... But again, this can take many minutes of your time if you computer is so heavily loaded that it is writing continually to swap.
SIG TERM exec cpu_broken.sh; reconvene; clear screen; clear thought_processes; continue...
Is there a better solution?