Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start a sub-process in Windows?

Tags:

fork

windows

In POSIX, there is the fork() function to create a sub-process. How can I achieve fork()'s functionality in Windows?

like image 318
Mr.Tu Avatar asked Feb 05 '12 08:02

Mr.Tu


People also ask

How do I start subprocess?

To start a new process, or in other words, a new subprocess in Python, you need to use the Popen function call. It is possible to pass two parameters in the function call. The first parameter is the program you want to start, and the second is the file argument.

Can we use subprocess in Windows?

Windows Constants (Flags) IMO, subprocess is more POSIX friendly, there are functions are only supporting on Unix environment. If you want to achieve some similar features on Windows, you may need to read through what Flags available for you.

How do I get output to run from subprocess?

To capture the output of the subprocess. run method, use an additional argument named “capture_output=True”. You can individually access stdout and stderr values by using “output. stdout” and “output.

What is a sub process in programming?

A subprocess is a task that is created by a process to complete a task within the parent process. Let's expand on that; a process is a task performed by the program during its execution. In many, if not all cases, processes usually have smaller tasks that need to be completed before the process can end.


1 Answers

There is no direct equivalent of fork() on Windows.

CreateProcess() is the native function that can be used to create a new process (but, again, the semantics are rather different to fork()'s).

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.

If you don't care about the cloning aspect of fork(), then CreateProcess() should do just fine.

like image 79
NPE Avatar answered Sep 28 '22 05:09

NPE