【发布时间】:2019-11-05 20:10:54
【问题描述】:
我是 python 线程的新手。我试图了解从 python 线程调用 os.system() 时会发生什么。我知道线程确实共享文件描述符、堆、代码和全局变量。我还读到 os.system(cmd) 创建了一个新的子外壳,并在那里执行提供的 cmd。
我的问题是,当 python 线程调用 os.system(cmd) 并且 cmd 执行“./test.exe input_file.dat”时,./test.exe 的进程是否共享任何内容(即输入文件、地址空间,堆等)与python线程?换句话说, os.system(cmd) 是否创建了一个与调用者进程或线程无关的新进程?
下面,我提供了我写的python代码。
#!/usr/bin/python
import threading
import os
semaphore = threading.Semaphore(3)
def run_command(cmd):
with semaphore:
os.system(cmd)
for i in range(3):
threading.Thread(target=run_command, args=("./test.exe input_file.dat", )).start()
【问题讨论】:
标签: python linux multithreading system-calls