sigint

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

好久不见. 提交于 2019-12-17 21:49:22
问题 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 gracefully. Thus, CTRL-C must not reach the server process. If I capture the KeyboardInterrupt exception or overwrite the SIGINT-handler in python, the server process still receives the CTRL-C and stops immediately. So my question is: How to prevent

Perl trapping Ctrl-C (sigint) in bash

﹥>﹥吖頭↗ 提交于 2019-12-13 19:13:25
问题 I'm reading How do we capture CTRL ^ C - Perl Monks, but I cannot seem to get the right info to help with my problem. The thing is - I have an infinite loop, and 'multiline' printout to terminal ( I'm aware I'll be told to use ncurses instead - but for short scripts, I'm more comfortable writing a bunch of printf s ). I'd like to trap Ctrl-C in such a way, that the script will terminate only after this multiline printout has finished. The script is (Ubuntu Linux 11.04): #!/usr/bin/env perl

C++: Continue execution after SIGINT

喜你入骨 提交于 2019-12-12 13:33:23
问题 Okay, I am writing a program that is doing some pretty heavy analysis and I would like to be able to stop it quickly. I added signal(SIGINT, terminate); to the beginning of main and defined terminate like: void terminate(int param){ cout << endl << endl << "Exit [N]ow, or [A]fter this url?" << endl; std::string answer; cin >> answer; if(answer[0] == 'n' || answer[0] == 'N'){ terminateParser(); exit(1); }else if(answer[0] == 'a' || answer[0] == 'A'){ quitAfterUrl = true; } } In linux, this

Java signal handling and then return to main program

时间秒杀一切 提交于 2019-12-11 18:09:00
问题 MI have a program that starts with for loop and it spins for 10 times, and one loop lasts one second. I need to handle a signal (CTRL+C) and while handling it, it should do it's own for loop, and after it stops, then I should return to the main loop. I've managed to do almost everything above, but the loops don't execute separately. They do it parallel. Hope you can help... thanks :) BTW, my code is: import sun.misc.Signal; import sun.misc.SignalHandler; public class MySig { public static

Ctrl+C not killing Sinatra + EM::WebSocket servers

纵然是瞬间 提交于 2019-12-11 11:16:35
问题 I'm building a Ruby app that runs both an EM::WebSocket server as well as a Sinatra server. Individually, I believe both of these are equipped to handle a SIGINT. However, when running both in the same app, the app continues when I press Ctrl+C. My assumption is that one of them is capturing the SIGINT, preventing the other from capturing it as well. I'm not sure how to go about fixing it, though. Here's the code in a nutshell: require 'thin' require 'sinatra/base' require 'em-websocket'

How to clean up local data in SIGINT handler

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 10:29:44
问题 I need to execute clean up functions in SIGINT handler, but I can't pass local data to it. Here an example: int main(int argc, char *argv[]) { struct database *db = db_cursor(); sockfd_t master_socket = init_server(); signal(SIGINT, sigint_handler); while (1) { // accepting connections } } void sigint_handler(int s) { destroy_db(db); shutdown(master_socket, SHUT_RDWR); close(master_socket); exit(EXIT_SUCCESS); } How can I implement such behaviour? I've tried make this variables are global,

Prevent SIGINT from closing child process in bash script

荒凉一梦 提交于 2019-12-11 03:42:43
问题 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 the child process. How can I prevent this from happening? edit: here's the script, don't critique my skills too much.. #!/bin/bash trap "interruptHandler" SIGINT inInterrupt=false; quit=false; if [ -z ${cachedir+x} ]; then cachedir=~/.cache

delegate SIGINT signal to child process and then cleanup and terminate the parent

老子叫甜甜 提交于 2019-12-11 02:59:44
问题 I have a main python(testmain.py) script that executes another python script(test.py) using subprocess.Popen command. When I press Ctrl-C , I want the child to exit with exit code 2 and then the parent to display that exit code and then terminate . I have signal handlers in both parent and child scripts. testmain.py def signal_handler(signal, frame): print "outer signal handler" exit(2) signal.signal(signal.SIGINT, signal_handler) def execute() proc=subprocess.Popen("python test.py",shell

Control-C kills Ipython in git bash on Windows 7

北城余情 提交于 2019-12-10 20:17:50
问题 After so many years cruising on Linux, I am back on a freaking Windows environment. I use Ipython, and I launch it in git bash. It would be hard for me to use something else, since the environment is configured to use this at my office. So, when I launch Ipython, and I mistakenly launch an infinite loop, or some bad code that takes ages to execute, I use ctrl-c. This kills Ipython, and it's pretty annoying. I did not find any way to circumvene this or another key that would do the trick. Any

Can R interpret a SIGINT/SIGTERM and execute a process as a result?

陌路散爱 提交于 2019-12-10 18:49:05
问题 Is there anyway to capture a SIGINT or SIGTERM from the shell in R so that I can try to execute some graceful exit code? So far, I haven't found anything in my search. 来源: https://stackoverflow.com/questions/30823237/can-r-interpret-a-sigint-sigterm-and-execute-a-process-as-a-result