如何将Ctrl-C ssh -t 发送到 Popen() 对象中的多个进程?
我有一些Python代码可以在远程主机上启动一个脚本:
# kickoff.py
# i call 'ssh' w/ the '-t' flag so that when i press 'ctrl-c', it get's
# sent to the script on the remote host. otherwise 'ctrol-c' would just
# kill things on this end, and the scr
这段python代码在无限循环中运行fbi,即使存在ctrl-C的陷阱。 import os
var = 1
try:
while var == 1:
os.system("sleep 5; kill $(pgrep fbi); sudo fbi -a image1.jpg")
except KeyboardInterrupt:
kill $(pgrep fbi)
pass 我按下ctrl-C,屏幕闪烁,image1又启动了。现在我知道python运行正常了,因为这段代码是通过ctrl-C退出的 import os
var = 1
x
运行gdb cmd时,我可以通过Ctrl-C手动停止cmd。这将调用调试器并让我检查内存。
在pwntools中,我可以附加gdb,还可以通过在gdb窗口中按Ctrl-C来手动停止该进程。我希望能够从pwntools脚本以编程方式完成此操作:类似于:
if output != expected:
io.gdb.ctrlc() # break, let me use gdb
这不一定需要pwntools的答案。GDB有一个强大的Python API,但我找不到等同于“中断进程,就好像有人按下了Ctrl-C”。有没有办法做到这一点,通过GDB Python API或通过pwntools方法
在Python2.7中调试脚本时,我偶尔会注入pdb.set_trace() (请注意,我实际上使用的是ipdb),例如:
import ipdb as pdb
try:
do_something()
# I'd like to look at some local variables before running do_something_dangerous()
pdb.set_trace()
except:
pass
do_something_dangerous()
我通常从shell运行我的脚本,例如
python my_script.py
有时在
我正在构建一个简单的控制台应用程序,它可以启动计时器并执行一些操作。如果用户按下Ctrl-C,我想关闭。
当我对此进行编码时,应用程序检测到Ctrl-C,但随后挂起且从不关闭。我做错了什么?
代码如下:
using System;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
private static readonly AutoResetEvent _closeEvent = new AutoResetEvent(false);
static void Ma