sigint

How to pass SIGINT to child process with Python subprocess.Popen() using shell = true

眉间皱痕 提交于 2019-12-04 12:18:48
I am currently trying to write (Python 2.7.3) kind of a wrapper for GDB, which will allow me to dynamically switch from scripted input to interactive communication with GDB. So far I use self.process = subprocess.Popen(["gdb vuln"], stdin = subprocess.PIPE, shell = True) to start gdb within my script. ( vuln is the binary I want to examine) Since a key feature of gdb is to pause the execution of the attached process and allow the user to inspect registers and memory on receiving SIGINT (STRG+C) I do need some way to pass a SIGINT signal to it. Neither self.process.send_signal(signal.SIGINT)

Python SIGINT not catched

丶灬走出姿态 提交于 2019-12-04 11:53:51
I don't manage to understand why my SIGINT is never catched by the piece of code below. #!/usr/bin/env python from threading import Thread from time import sleep import signal class MyThread(Thread): def __init__(self): Thread.__init__(self) self.running = True def stop(self): self.running = False def run(self): while self.running: for i in range(500): col = i**i print col sleep(0.01) global threads threads = [] for w in range(150): threads.append(MyThread()) def stop(s, f): for t in threads: t.stop() signal.signal(signal.SIGINT, stop) for t in threads: t.start() for t in threads: t.join() To

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

我的梦境 提交于 2019-12-04 05:24:34
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 are pretty much all over the place, and I haven't been able implement any of them into this small script: import asyncio import datetime import functools import signal async def display_date(loop): end_time = loop.time() + 5.0 while True: print(datetime.datetime.now()) if (loop.time() + 1.0) >= end_time: break await asyncio.sleep(1) def stopper

Why Linux always output “^C” upon pressing of Ctrl+C?

耗尽温柔 提交于 2019-12-03 13:54:26
I have been studying signals in Linux. And I've done a test program to capture SIGINT. #include <unistd.h> #include <signal.h> #include <iostream> void signal_handler(int signal_no); int main() { signal(SIGINT, signal_handler); for (int i = 0; i < 10; ++i) { std::cout << "I'm sleeping..." << std::endl; unsigned int one_ms = 1000; usleep(200* one_ms); } return 0; } void signal_handler(int signal_no) { if (signal_no == SIGINT) std::cout << "Oops, you pressed Ctrl+C!\n"; return; } While the output looks like this: I'm sleeping... I'm sleeping... ^COops, you pressed Ctrl+C! I'm sleeping... I'm

How to stop SIGINT being passed to subprocess in python?

假装没事ソ 提交于 2019-12-03 09:10:35
问题 My python script intercepts the SIGINT signal with the signal process module to prevent premature exit, but this signal is passed to a subprocess that I open with Popen. is there some way to prevent passing this signal to the subprocess so that it also is not exited prematurely when the user presses ctrl-c? 回答1: You are able to re-assign the role of ctrl-c using the tty module, which allows you to manipulate the assignment of signals. Be warned, however, that unless you put them back the way

Trap signal in child background process

♀尐吖头ヾ 提交于 2019-12-03 05:46:57
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 2 done When running this and later do kill -SIGINT (pid) Everything works as expected, it prints 'trapped' and exits. Now, if I start the same script from a parent script like this : #!/bin/bash echo "starting the child" ./child.sh & Then the child does not trap the signal anymore.... ? After changing to use SIGTERM instead of SIGINT, it seems to be working correctly

Sending ctrl-c to specific screen session

孤人 提交于 2019-12-02 19:34:32
I am designing a script to launch a process inside a named screen session. as_user "screen -p 0 -S **$command** -X eval 'stuff \"wine LFS.exe /cfg=**$command**.cfg\"\015'" So bash myscript.sh start test will create a screen named test and run the test.cfg with the software. Now I want my script to access the specific screen session and do a CTRL + C to stop the running process so i can kill the screen session. Something like this: as_user "screen -p 0 -S **$command** **... kill the process with ctrl-c...**" as_user "screen -p 0 -S **$command** -X eval 'stuff \"exit\"\015'" I don't quite

Interrupting Python raw_input() in a child thread with ^C/KeyboardInterrupt

陌路散爱 提交于 2019-12-01 17:07:34
In a multithreaded Python program, one thread sometimes asks for console input using the built-in raw_input() . I'd like to be able to be able to close the program while at a raw_input prompt by typing ^C at the shell (i.e., with a SIGINT signal). However, when the child thread is executing raw_input, typing ^C does nothing -- the KeyboardInterrupt is not raised until I hit return (leaving raw_input). For example, in the following program: import threading class T(threading.Thread): def run(self): x = raw_input() print x if __name__ == '__main__': t = T() t.start() t.join() Typing ^C does

SIGINT handling and getline

て烟熏妆下的殇ゞ 提交于 2019-12-01 07:14:10
问题 I wrote this simple program: void sig_ha(int signum) { cout<<"received SIGINT\n"; } int main() { string name; struct sigaction newact, old; newact.sa_handler = sig_ha; sigemptyset(&newact.sa_mask); newact.sa_flags = 0; sigaction(SIGINT,&newact,&old); for (int i=0;i<5;i++) { cout<<"Enter text: "; getline(cin,name); if (name!="") cout<<"Text entered: "<<name; cout<<endl; } return 0; } If I hit ctrl-c while the program waits for input I get the following output: Enter text: received SIGINT Enter

Readline: Get a new prompt on SIGINT

泪湿孤枕 提交于 2019-11-30 18:31:49
I've got code similar to the following, using readline: #include <errno.h> #include <error.h> #include <getopt.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <readline/readline.h> #include <readline/history.h> void handle_signals(int signo) { if (signo == SIGINT) { printf("You pressed Ctrl+C\n"); } } int main (int argc, char **argv) { //printf("path is: %s\n", path_string); char * input; char * shell_prompt = "i-shell> "; if (signal(SIGINT, handle_signals) == SIG_ERR) { printf("failed to register interrupts with kernel\n"); } //set up custom