How do global cancel/exit commands work in bash?
- by SecurityGate
As I have done multiple times before, I've written bash scripts, and just general commands that go nowhere. They just blink the little command line cursor at me for infinity until I control+C the command. When I do cancel the command, what exactly is going on when I do this? Am I somehow stopping and killing the current PID I'm working on? Does it jump to a different run-level and execute something to terminate the command?
On a slightly different note, I've never been able to figure out how to set up something like this in a script or program I've worked on. Since I mostly program in Ruby, can I setup something like a certain key press stops the program? Every time I've looked into doing something similar, I always end up getting hung up when it comes to user input, whether that is a loop waiting for a condition, or something like this:
def Break()
user_break = gets.strip
end
def Main()
Function1()
Break()
Function2()
Break()
[...]
end
It seems and is incredibly bulky, and definitely isn't easily scaled up or down.