如何在Windows中启动子流程? [英] How can I start a sub-process in Windows?
问题描述
在POSIX中,有一个fork()
函数来创建一个子进程.如何在Windows中实现fork()
的功能?
In POSIX, there is the fork()
function to create a sub-process. How can I achieve fork()
's functionality in Windows?
推荐答案
在Windows上没有直接等效的fork()
.
There is no direct equivalent of fork()
on Windows.
CreateProcess()
是可用于创建新进程的本机函数(但同样,其语义与fork()
的语义完全不同).
CreateProcess()
is the native function that can be used to create a new process (but, again, the semantics are rather different to fork()
's).
换句话说,在Unix上,进程可以廉价地创建其自身的克隆.在Windows上没有便宜的方法可以做到这一点.
To put this another way, on Unix it is possible for a process to cheaply create a clone of itself. There is no inexpensive way to do this on Windows.
如果您不关心fork()
的克隆方面,那么CreateProcess()
应该就可以了.
If you don't care about the cloning aspect of fork()
, then CreateProcess()
should do just fine.
这篇关于如何在Windows中启动子流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!