subprocess.Popen()和os.fork()有什么区别? [英] What is the difference between subprocess.Popen() and os.fork()?

查看:176
本文介绍了subprocess.Popen()和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆