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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With