How to pass SIGINT to child process with Python subprocess.Popen() using shell = true(如何使用 shell = true 使用 Python subprocess.Popen() 将 SIGINT 传递给子进程)
问题描述
我目前正在尝试为 GDB 编写 (Python 2.7.3) 一种包装器,这将允许我从脚本输入动态切换到与 GDB 的交互式通信.
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.
到目前为止我使用
self.process = subprocess.Popen(["gdb vuln"], stdin = subprocess.PIPE, shell = True)
在我的脚本中启动 gdb.(vuln
是我要检查的二进制文件)
to start gdb within my script. (vuln
is the binary I want to examine)
由于 gdb 的一个关键特性是暂停附加进程的执行并允许用户在接收到 SIGINT (STRG+C) 时检查寄存器和内存,因此我确实需要一些方法来将 SIGINT 信号传递给它.
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.
没有
self.process.send_signal(signal.SIGINT)
也没有
os.kill(self.process.pid, signal.SIGINT)
或
os.killpg(self.process.pid, signal.SIGINT)
为我工作.
当我使用这些功能之一时,没有响应.我想这个问题是由使用 shell=True
引起的.但是,在这一点上,我真的没有想法.这次即使是我的老朋友 Google 也无法真正帮助我,所以也许你可以帮助我.提前致谢.
When I use one of these functions there is no response. I suppose this problem arises from the use of shell=True
. However, at this point I am really out of ideas.
Even my old friend Google couldn't really help me out this time, so maybe you can help me. Thank's in advance.
干杯,迈克
推荐答案
这对我有用:
import signal
import subprocess
try:
p = subprocess.Popen(...)
p.wait()
except KeyboardInterrupt:
p.send_signal(signal.SIGINT)
p.wait()
这篇关于如何使用 shell = true 使用 Python subprocess.Popen() 将 SIGINT 传递给子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 shell = true 使用 Python subprocess.Popen() 将 SIGINT 传递给子进程


基础教程推荐
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01