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

315 questions
138
votes
4 answers

How can I catch a ctrl-c event?

How do I catch a Ctrl+C event in C++?
Scott
  • 4,685
  • 10
  • 52
  • 72
95
votes
17 answers

Can I send a ctrl-C (SIGINT) to an application on Windows?

I have (in the past) written cross-platform (Windows/Unix) applications which, when started from the command line, handled a user-typed Ctrl-C combination in the same way (i.e. to terminate the application cleanly). Is it possible on Windows to send…
Matthew Murdoch
  • 28,946
  • 26
  • 89
  • 125
43
votes
5 answers

Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT

I am currently working on a wrapper for a dedicated server running in the shell. The wrapper spawns the server process via subprocess and observes and reacts to its output. The dedicated server must be explicitly given a command to shut down…
robert
  • 3,017
  • 3
  • 25
  • 35
42
votes
3 answers

Is destructor called if SIGINT or SIGSTP issued?

I have a class with a user-defined destructor. If the class was instantiated initially, and then SIGINT is issued (using CTRL+C in unix) while the program is running, will the destructor be called? What is the behaviour for SIGSTP (CTRL + Z in…
SkypeMeSM
  • 2,876
  • 7
  • 40
  • 59
39
votes
3 answers

Python: Catch Ctrl-C command. Prompt "really want to quit (y/n)", resume execution if no

I have a program that may have a lengthy execution. In the main module I have the following: import signal def run_program() ...time consuming execution... def Exit_gracefully(signal, frame): ... log exiting information ... ... close…
Colin M
  • 391
  • 1
  • 3
  • 3
36
votes
2 answers

What is the difference between Ctrl-C and SIGINT?

I have been debugging a Python program which segfaults after receiving a KeyboardInterrupt exception. This is normally done by pressing Ctrl+C from the shell. To test if a particular code change fixed the bug, I had a small shell-script that sent…
Belorn
  • 371
  • 1
  • 3
  • 5
28
votes
5 answers

Sending SIGINT (Ctrl-C) to program running in Eclipse Console

I have setup a run configuration in Eclipse and need to send SIGINT (Ctrl+C) to the program. There is cleanup code in the program that runs after SIGINT, so pressing Eclipse's "Terminate" buttons won't work (they send SIGKILL I think). Typing CTRL+C…
vsekhar
  • 4,050
  • 4
  • 20
  • 22
26
votes
3 answers

How to properly handle SIGINT with Express.js?

I need to do some useful things when my Express.js service is stopped by SIGINT. Using Express.js version 3.0.6, I understand that this should work: var express = require('express'); var app = express(); var server =…
Jacob Marble
  • 24,696
  • 18
  • 62
  • 76
20
votes
2 answers

Catching SIGTERM vs catching SIGINT

In Node.js servers, is there any difference between catching SIGTERM vs catching SIGINT? I thought processes were not supposed to be able to prevent shutdown upon a SIGINT? process.once('SIGINT', function (code) { console.log('SIGINT…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
19
votes
2 answers

How to gracefully terminate an asyncio script with Ctrl-C?

I've read every post I could find about how to gracefully handle a script with an asyncio event loop getting terminated with Ctrl-C, and I haven't been able to get any of them to work without printing one or more tracebacks as I do so. The answers…
JK Laiho
  • 3,252
  • 5
  • 30
  • 36
18
votes
1 answer

Capturing SIGINT using KeyboardInterrupt exception works in terminal, not in script

I'm trying to catch SIGINT (or keyboard interrupt) in Python 2.7 program. This is how my Python test script test looks: #!/usr/bin/python import time try: time.sleep(100) except KeyboardInterrupt: pass except: print "error" Next I…
Velda
  • 527
  • 1
  • 5
  • 20
18
votes
2 answers

Cygwin CTRL-C (Signal Interrupts) not working properly - JVM Shutdown Hooks not starting

I'm working on a Java application that utilises shutdown hooks in order to clean up on termination/interruption of the program, but I've noticed that Cygwin's implementation of CTRL-C doesn't seem to trigger the shutdown hooks. On the surface it…
Quetzalcoatl
  • 2,897
  • 2
  • 15
  • 26
17
votes
2 answers

How can I catch SIGINT in threading python program?

When using threading module and Thread() class, SIGINT (Ctrl+C in console) could not be catched. Why and what can I do? Simple test program: #!/usr/bin/env python import threading def test(suffix): while True: print "test", suffix def…
Marko Kevac
  • 2,572
  • 24
  • 46
16
votes
2 answers

Unable to trap SIGINT signal in a background shell

I am unable to trap a signal when running in a child / background process. Here is my simple bash script: #!/bin/bash echo "in child" trap "got_signal" SIGINT function got_signal { echo "trapped" exit 0 } while [ true ]; do sleep…
Matthieu
  • 15,277
  • 10
  • 54
  • 83
16
votes
4 answers

CURL cannot be killed by a PHP SIGINT with custom signal handler

I have a PHP command line app with a custom shutdown handler:
Jonathan
  • 10,693
  • 16
  • 74
  • 110
1
2 3
20 21