【发布时间】:2020-07-16 03:07:08
【问题描述】:
我正在创建一个脚本,它将启动一些线程,并在二进制文件上运行输入。用法是python3 script.py binary input.txt。这是遇到此错误的可重现段:
from pwn import *
import threading
inputFile = ""
try:
inputFile = open(sys.argv[2], 'r')
inputStr = inputFile.read().strip()
inputFile.close()
except OSError:
sys.exit()
def run(testStr) :
p = process("./"+sys.argv[1])
p.sendline(testStr)
p.shutdown()
return p.poll(block = True)
def opens() :
while True:
run(inputStr)
for i in range(0,10):
thread = threading.Thread(target = opens)
thread.start()
运行 5 秒左右后,我遇到了这个错误,以及错误:out of pty devices。
我在 ubuntu 20.04 上运行。
【问题讨论】:
-
或许可以阅读pthread tutorial。请注意,Python 有一个GIL。下载Python的源代码学习一下,是开源的。另见errno(3)
-
我添加了一些可重现的代码。我只是不明白如果我们在启动一个新进程之前等待每个进程退出,为什么操作系统会遇到这个问题:(p.poll(block=True))。感谢您的回复。
-
轮询应该阻塞,直到进程完成,这意味着最多将有 10 个进程同时运行:docs.pwntools.com/en/stable/tubes/…
标签: python-3.x multithreading process pwntools