Information Technology Reference
In-Depth Information
//simplifiedversionofthecalltocreateaprocesswithargumentsonWindows
simplified:booleanCreateProcess(char*prog,char*args)
//Startthechildprocess
if(!CreateProcess(NULL, //Nomodulename(usecommandline)
argv[1], //Commandline
NULL, //Processhandlenotinheritable
NULL, //Threadhandlenotinheritable
FALSE, //SethandleinheritancetoFALSE
0,
//Nocreationflags
NULL,
//Useparent'senvironmentblock
NULL,
//Useparent'sstartingdirectory
&si,
//PointertoSTARTUPINFOstructure
&pi)
//PointertoPROCESS_INFORMATIONstructure
)
Figure3.3: Excerpt from an example of how to use the Windows CreatePro-
cess system call. The first two arguments specify the program and its argu-
ments; the rest concern aspects of the process runtime environment.
Create and initialize a new address space
Load the program prog into the address space
Copy arguments args into memory in the address space
Initialize the hardware context to start execution at \start"
Inform the scheduler that the new process is ready to run
Unfortunately, there are quite a few aspects of the process that the parent
might like to control, such as: its privileges, where it sends its input and output,
what it should store its files, what to use as a scheduling priority, and so forth.
We can't trust the child process itself to set its own privileges and priority, and
it would be inconvenient to expect every application to include code for figuring
out its context. So the real interface to CreateProcess is quite a bit more
complicated in practice, given in Figure 3.3.
3.1.2
UNIX process management
UNIX takes a different approach to process management, one that is complex in
theory and simple in practice. UNIX splits CreateProcess in two steps, called
fork and exec , illustrated in Figure 3.4.
UNIX fork creates a complete copy of the parent process, with one key
exception described below. This copy can then do whatever is necessary to
set up the context of the child. Because the child process is still running the
code of the parent, the copy can be trusted to set up privileges and priorities
correctly. Once the context is set, the copy then calls UNIX exec to copy in the
 
Search WWH ::




Custom Search