sigint

What is the difference between Ctrl-C and SIGINT?

为君一笑 提交于 2019-11-27 01:16:35
问题 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 SIGINT to the program at random time after start-up. The problem I have is that sending Ctrl+C seems to have a different effect on the program than sending the signal SIGINT and is thus not causing the bug to appear, so I quite wonder what the

What happens to a SIGINT (^C) when sent to a perl script containing children?

巧了我就是萌 提交于 2019-11-26 21:33:35
问题 I have a Perl script that forks. Each fork runs an external program, parses the output, and converts the output to a Storable file. The Storable files are then read in by the parent and the total data from each of the children are analyzed before proceeding onto a repeat of the previous fork or else the parent stops. What exactly happens when I issue a ^C while some of the children are still running the external program? The parent perl script was called in the foreground and, I presume,

Is destructor called if SIGINT or SIGSTP issued?

ε祈祈猫儿з 提交于 2019-11-26 12:08:50
问题 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 unix)? 回答1: No, by default, most signals cause an immediate, abnormal exit of your program. However, you can easily change the default behavior for most signals. This code shows how to make a signal exit your program normally, including calling all the

How can I catch a ctrl-c event?

纵然是瞬间 提交于 2019-11-26 11:33:17
How do I catch a Ctrl + C event in C++? Gab Royer signal isn't the most reliable way as it differs in implementations. I would recommend using sigaction . Tom's code would now look like this : #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> void my_handler(int s){ printf("Caught signal %d\n",s); exit(1); } int main(int argc,char** argv) { struct sigaction sigIntHandler; sigIntHandler.sa_handler = my_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); pause(); return 0; } Chris Smith For a Windows

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

孤者浪人 提交于 2019-11-26 11:03:04
问题 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 any open files ... sys.exit(0) if __name__ == \'__main__\': signal.signal(signal.SIGINT, Exit_gracefully) run_program() This works fine, but I\'d like the possibility to pause execution upon catching SIGINT, prompting the user if they would really like to quit,

How can I catch a ctrl-c event?

*爱你&永不变心* 提交于 2019-11-26 02:27:33
问题 How do I catch a Ctrl + C event in C++? 回答1: signal isn't the most reliable way as it differs in implementations. I would recommend using sigaction . Tom's code would now look like this : #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> void my_handler(int s){ printf("Caught signal %d\n",s); exit(1); } int main(int argc,char** argv) { struct sigaction sigIntHandler; sigIntHandler.sa_handler = my_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags

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

不想你离开。 提交于 2019-11-25 23:38:09
问题 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 a Ctrl - C /SIGINT/equivalent to a process from another (unrelated) process to request that it terminate cleanly (giving it an opportunity to tidy up resources etc.)? 回答1: The closest that I've come to a solution is the SendSignal 3rd party app.