Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle Ctrl-C interrupt in nim?

Tags:

nim-lang

If I press Ctrl-C while my program is running it exits and prints SIGINT: Interrupted by Ctrl-C.

How do I ignore the Ctrl-C interrupt in Nim on Linux? Thanks in advance.

like image 476
joe Avatar asked Feb 15 '19 16:02

joe


People also ask

What is CTRL C interrupt?

In many command-line interface environments, control+C is used to abort the current task and regain user control. It is a special sequence that causes the operating system to send a signal to the active program.

What signal is Ctrl C?

While in a command line such as MS-DOS, Linux, and Unix, Ctrl + C is used to send a SIGINT signal, which cancels or terminates the currently-running program. For example, if a script or program is frozen or stuck in an infinite loop, pressing Ctrl + C cancels that command and returns you to the command line.


Video Answer


1 Answers

You can control the behaviour of Ctrl+C with setControlCHook:

proc ctrlc() {.noconv.} =
  echo "Ctrl+C fired!"

setControlCHook(ctrlc)

Now CtrlC calls the ctrlc procedure. It's up to that procedure to ignore the SIGINT, or to clean the house and exit with quit.

like image 120
xbello Avatar answered Oct 19 '22 02:10

xbello