🆘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 interruptsCtrl + C is one such interrupt.

Processes generate signals in three basic situations:

  1. Unexcepted situation occurs.
  2. Use of key combinations like Ctrl + C or Ctrl + Z on the console by the user.
  3. Timer expires, the CPU usage limit applied to the application is high etc.

Common signals that I have encountered,

Signal Name

Signal Number

Singal Action*

Description

SIGHUP

1

Term

Hang up detected on controlling terminal or death of controlling process

SIGINT

2

Term

Keyboard interrupt (usually Ctrl-C)

SIGQUIT

3

Term

Manual-interrupt(usually Ctrl-D)

SIGKILL

9

Term

Immediate process termination with no cleanup.

SIGSEGV

11

Core

Invalid memory reference

*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🤔

Popular posts from this blog

What really is a Hypertext?

Browser Rendering Phase

Crypto crypto everywhere but not a token to bet your life on