🆘Intterupts got me thinking..
I was unaware of an infinite loop in a Go program I wrote. Thankfully, I knew Ctrl + C could get me out of this never-ending program execution. But I was curious about the way Ctrl + C interrupts my program execution.
What makes them so powerful is that they can stop the execution of a running program.
So, why does this mechanism exist?
These are my findings,
When I Ctrl + C on a running Go program it exits as follows,
exit status 0xc000013a
Signals are an integral part of operating systems. The signalling mechanism is commonly known as interrupts. Ctrl + C is one such interrupt.
Processes generate signals in three basic situations:
- Unexcepted situation occurs.
- Use of key combinations like Ctrl + C or Ctrl + Z on the console by the user.
- Timer expires, the CPU usage limit applied to the application is high etc.
Common signals that I have encountered,
*The process is terminated resulting in an abnormal process termination.
*The process is terminated after creating a core dump file.
What should I make of it?
Each signal interrupt defines some default ways of how the process behaves when the signal is delivered to them.
The 'Term' & 'Core' actions defined above is basically that. There are actions that define the signal to be simply ignored.
🌟But a more graceful way of handling a signal is to catch the signal with a signal handler, a programmer-defined function that is automatically invoked when the signal is delivered.
A write-up on gracefully handling signals using Go would make a great post I think🤔