subprocess.Popen()和os.fork()有什么区别? [英] What is the difference between subprocess.Popen() and os.fork()?
问题描述
似乎 subprocess.Popen()和 os.fork()都可以创建一个子级过程.但是,我想知道两者之间的区别.您什么时候使用哪个?我尝试查看它们的源代码,但在我的计算机上找不到fork()的源代码,还不清楚Popen如何在Unix计算机上工作.
It seems like subprocess.Popen() and os.fork() both are able to create a child process. I would however like to know what the difference is between both. When would you use which one? I tried looking at their source code but I couldn't find fork()'s source code on my machine and it wasn't totally clear how Popen works on Unix machines.
有人可以详细说明吗?
谢谢
推荐答案
subprocess.Popen
让我们在自己的进程中执行任意程序/命令/可执行文件/任何东西.
subprocess.Popen
let's you execute an arbitrary program/command/executable/whatever in its own process.
os.fork
仅允许您创建一个子进程,该子进程将在调用它的确切行中执行相同脚本.顾名思义,它简单地"将当前进程分为2个.
os.fork
only allows you to create a child process that will execute the same script from the exact line in which you called it. As its name suggests, it "simply" forks the current process into 2.
os.fork
仅在Unix上可用,而subprocess.Popen
是跨平台的.
os.fork
is only available on Unix, and subprocess.Popen
is cross-platfrom.
这篇关于subprocess.Popen()和os.fork()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!