THE GOAL:
To create an WNT program that will fork & reap many children over it's
lifetime. It will be NON-GRAPHICAL.
THE QUESTION:
Should I use spawn or CreateProcess ? It would appear that spawn
would be the easy choice, as all examples that I've seen using
CreateProcess involve setting up a message loop and some other
graphical things...
This is going to be a fairly big program, and I'm wondering if there
are hidden advantages to using CreateProcess over spawn.
All comments/suggestions welcome
--
=================================================================
Joe Pasko
"There are two major products that come out of Berkeley: LSD and UNIX.
We don't believe this to be a coincidence." - Jeremy S. Anderson
CreateProcess is definitely the API to use - it has numerous benefits.
It's outwardly more "intimidating" to use, but it gives you a great deal
more control over what's going on.
I'd guess that you're going to want to wait for your "child" processes
to terminate, retrieve their exit codes, etc, and for that you'll need
the process handle. CreateProcess gives you back the process handle;
spawn doesn't.
CreateProcess has nothing to do with message loops, etc. You can use it
in a straight console application.
Chris
--------------------------------------------------------------------------
Chris Marriott, Warrington, UK | Author of SkyMap v3 award-winning
ch...@chrism.demon.co.uk | shareware Win31/Win95 planetarium.
For full info, see http://www.execpc.com/~skymap
Author member of Association of Shareware Professionals (ASP)
--------------------------------------------------------------------------
Hi,
If you really want to write Win32 programs, you shoud use the
CreateProcess procedure to create children.
Remember that for Win32 programs:
- Console application are available, for such application you don't
have to write a message loop and your application starts with the
procedure main.
- Created processes are not children, there is not relation between
the creathor and created processes. The start of the created process is
in main (very different from fork), it's a bit like fork+exec.
- Process do not share adress space and do not share any ressources
(mutex, event, files handles ...). You must use the heritage or
re-open named ressource to share access of ressources between your
processes. You can use file mapping to get shared memory.
I hope this will be usefull.
--
Jean-Michel Combe
(french computer consultant)
Generally there is no advantage of CreateProcess over spawn, with create
process there is more control over how you wan't the program to run, in
a separate window (your program in this case), or in another window, have
a console, suspended, etc.
Also if you plan to start off more than one process at a time and then
wait for all the processes to complete before continuing on in the
process that started them it is generally better to do this using
CreateProcess and then WaitForMultipleObjects to wait for each process
to complete.
As a final note depending on how the program is designed and how
often you are creating new processes it might be better to use threads
where you have multiple threads of execution in a single process each
getting a slice of the CPU's time. There is also less overhead in
threads than in processes.
If you have either Borland or MSVC++ you might want to look at the
online Help for the Windows API. Also the WIN32 SDK has a lot of
information. There are also a few books that have info on win32
programming, most of these are graphical based but a few have examples
using console applications.
Ron