Questions tagged [sigint]

On POSIX-compliant platforms, SIGINT is the signal sent to a process by its controlling terminal when a user wishes to interrupt the process.

On POSIX-compliant platforms, SIGINT is the signal sent to a process by its controlling terminal when a user wishes to interrupt the process.

Wikipedia: https://en.wikipedia.org/wiki/SIGINT_%28POSIX%29#SIGINT

369 questions
4
votes
0 answers

Mono application using Console.CancelKeyPress cannot be run in background

I have a console application in Mono under Linux that uses Console.CancelKeyPress to listen for SIGINT. However, this applications refuses to run in the background, as it always immediately gets stopped. Here's a reduced example: using System; using…
Sven
  • 21,903
  • 4
  • 56
  • 63
4
votes
3 answers

Why is my threading/multiprocessing python script not exiting properly?

I have a server script that I need to be able to shutdown cleanly. While testing the usual try..except statements I realized that Ctrl-C didn't work the usual way. Normally I'd wrap long running tasks like this try: ... except…
c00kiemonster
  • 22,241
  • 34
  • 95
  • 133
4
votes
1 answer

Perl trapping Ctrl-C with threads in bash

While I see how to have Perl trap Ctrl-C (sigint) in bash; I'm getting lost at why does it fail with threads; I'm trying the following script: #!/usr/bin/env perl use threads; use threads::shared; # for shared variables my $cnt :shared = 0; sub…
sdaau
  • 36,975
  • 46
  • 198
  • 278
4
votes
1 answer

How do I ensure the `SIGINT` signal handler is called as many times as `Ctrl+C` is pressed (with `longjmp`)?

Setup In the code below, which simply prints some text until it times out, I added a handler (onintr()) for SIGINT. The handler onintr() does the following: Resets itself as the default handler. Prints out some text. Calls longjmp(). Issue It…
gomfy
  • 637
  • 8
  • 16
4
votes
2 answers

Ignoring ctrl-c

I'm trying to write a shell and I'm at the point where I want to ignore CtrlC. I currently have my program ignoring SIGINT and printing a new line when the signal comes, but how can I prevent the ^C from being printed? When pressing CtrlC, here is…
samoz
  • 56,849
  • 55
  • 141
  • 195
4
votes
0 answers

Send SIGINT to running program in IntelliJ

As IntelliJ + Windows user, I'm running some applications by starting some "Configurations". The "Tool windows"/"Run" live show my aplication logs, and I've got left panel with "pause" or "stop" buttons. The stop button send a SIGKILL to the…
boly38
  • 1,806
  • 24
  • 29
4
votes
2 answers

bash not reacting to signals

Let's consider following script: #!/bin/bash while true ; do: ; done After running the script, the bash goes into loop, but can be interrupted (by pressing Ctrl-C or issuing kill -2 command) or terminated (by issuing kill command). All works…
Krzysztof
  • 73
  • 1
  • 4
4
votes
0 answers

Using SIGINT and SIGTSTP to handle foreground processes a unix shell

I have some questions regarding the use of SIGINT and SIGTSTP in relation to managing processes in my own unix shell. But first of the code here: void execute(vector argvv, bool x){ pid_t pid; int status; int error; …
4
votes
2 answers

Why the second SIGINT can't be captured on win32?

Below is my code to run on win32. #include "stdafx.h" #include void INThandler( int sig ) { printf( "Ctrl-C pressed\n" ); } int main () { signal( SIGINT, INThandler ); while (1) { } return 0; } The output of the…
yazou
  • 51
  • 4
4
votes
3 answers

Prevent SIGINT from closing child process in bash script

I am writing a bash script in which I wrote a handler to take care of when the user pressed Control+C, (by using trap interruptHandler SIGINT) but the SIGINT gets sent to both the bash script and the child process that is currently running, closing…
John Leuenhagen
  • 576
  • 7
  • 23
4
votes
1 answer

Signal handler, python

I have a multithreaded program and use the signal.signal(SIGINT,func) to kill all threads when ctrl c is pressed. The question I have is this: I have to call signal.signal(...) from main in python. Do I have to call that on a loop or can I just set…
Juli
  • 41
  • 1
4
votes
1 answer

How to pause the execution of a program after 10 seconds and get a backtrace?

A legacy program most likely gets into an infinite loop on certain pathological inputs. I have >1000 such instances, however, I suspect that the vast majority of them trigger the same bug. Therefore, I would like to reduce the >1000 instances to the…
Ali
  • 56,466
  • 29
  • 168
  • 265
4
votes
0 answers

Is it considered good practice to catch a KeyboardInterrupt in Python code?

I was working on a project recently that requires me to be writing data to and from files and I don't want to have to worry about files being corrupted if the script gets stopped via Ctrl+C. Now, this can be helped by making sure that files are open…
RPiAwesomeness
  • 5,009
  • 10
  • 34
  • 52
4
votes
1 answer

In bash, how to catch and handle SIGINT, without stopping the script?

It looks like trap on_sigint SIGINT just stop the script as soon as SIGINT is caught. Then, on_sigint is executed. Is it possible to handle SIGINT without stopping the script ?
loxaxs
  • 2,149
  • 23
  • 27
4
votes
4 answers

How to capture Ctrl-C and use it to exit an endless loop properly

I'm trying to run a program inside an endless loop because it sometimes dies for no reason. I would like to be able to hit Ctrl-C to prevent the program being restarted though. I don't want Ctrl-C to kill the program, just to wait until it dies,…
localhost
  • 1,253
  • 4
  • 18
  • 29