Hi Peter!
Post by Peter McleodOn Sun, 25 May 2003 21:43:21 -0400
[...]
Post by Greg Chicaressystem() is available--it's required by the C and
C++ standards. If you need something better on
http://www.byte.com/art/9410/sec14/art3.htm
system() is normally just a function which reuses fork()
^^^^^^^^
That is true for any Unix OS including Linux, because it has
"fork()" and the "exec()" family of calls. Windows simply does
not have them. I personally like your wording "normally",
but many people may contradict you.
Post by Peter Mcleodand execl(). I take it that system was built in a
different way under MinGW? If it does the trick though I
don't think I will need anything from the windows API (that
AIUI, in MinGW, "system()" is taken from the MS C runtime lib
which in turn probably uses "CreateProcess()".
Post by Peter Mcleodis, I'm endavouring to keep the code the same for windows
and linux/unix variations). Out of curiousity though - I
would like to know what method it's using internally.
I'll be investigating/trialing it soon then - not looking
for further response unless you want to add something.
IMNSHO, it depends on your requirements:
1) Using "fork()" only, you get a child process that executes
the same code as the parent (quite similar to multithreading,
but without sharing the global variables).
2) Using "fork()" + "exec()", you have parent and child run in
parallel, and they can communicate via pipes or other means.
3) If you need one-way communication via a pipe, use "popen()".
4) Using "system()", the parent process will wait for the child's
termination - there is no parallelism.
I do not know how to do 1) on Windows, others may tell you.
If you need 2), you have to use "CreateProcess()", so you will
have a Windows-only section of code.
If 3) or 4) is sufficient for you, "popen()" or "system()" is
the way to go, both are required by C and are in the MSVCRT lib.
HTH,
Joerg Bruehe
--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
(speaking only for himself)
mailto: ***@sql.de