lfk@athena.mit.edu (Lee F Kolakowski) (10/04/90)
Here is the scoop on the child processes in "C". Not MSDOS. All putatively ANSI compilers adhere to this. I use MSC and since version 4.0 It has followed these rules. spawn family: This family of functions takes either an argv style args or a NULL terminated list of arguments. There are four versions of each and *NONE* of these execute command.com unless command.com is the argument of the function. spawnl{pe} - "l" means list the argv[0] argument must be a complete pathname. "lp" list and path the argv[0] argument does not need to be a full path, the path will be searched. "le" list and environment the argv[0] argument must be a complete pathname. The environment can be modified and passed as a NULL terminated list to the sub process. "lpe" list, path, environment the argv[0] argument does not need to be a full path, the path will be searched. The environment can be modified and passed as a NULL terminated list to the sub process. spawnv{pe} - "v" means vector this means an argv like argument where argv[n+1] == NULL. all the different versions are just as specified above. All of the spawn family have a mode. In MSDOS the modes are P_OVERLAY and P_WAIT. P_NOWAIT and others are not implemented. P_WAIT says run the command specified with the arguments specified on top of the current process, and then return to the current process upon completion of the child. P_NOWAIT overlays the current process with the child. exec family: This is exactly the same as the spawn functions with P_NOWAIT as the mode. All eight functions as specified above execl{pe}, execv{pe}. Again unless command.com is the argument to be executed It is not loaded. system: loads command.com and executes the command specified. popen: runs the command specified under the command processor asynchronously. (Not really valid under MSDOS, but there are impletmentations of it. for example /* A test program */ #include <stdio.h> #include <process.h> main() { char * command = "ps"; spawnlp(P_WAIT, "ps.exe", (char *) NULL); /* the output of ps PID PPID SIZE DS Command 3087 258c 0728 3097 (sh.exe) c:/bin/sh.exe -R 0 <- my shell 37b0 37ef 003a 37eb FREE 0003 48 bytes 37ef 3087 1206 39f5 (test.exe) ./test.exe <- the test program 49f6 4a31 003a 4a31 37ef 02c0 4be3 c:/bin/ps.exe <- the process started by spawn on top 4cf2 FREE 5303 340016 bytes of the test program 9ff6 3087 000a*/ system("ps.exe"); /* The output of ps PID PPID SIZE DS Command 3087 258c 0728 3097 (sh.exe) c:/bin/sh.exe -R 0 <- my shell 37b0 37ef 003a 37eb FREE 0003 48 bytes 37ef 3087 1206 39f5 (test.exe) ./test.exe <- the test program 49f6 4a32 003b 4a32 4a32 00d3 4a32 (command.com) c:/bin/command.com <- the "system" 4b06 4a32 0039 4b40 4b7b 003a 4b7b 4a32 02c0 4d2d c:/bin/PS.EXE <- the process run by system 4e3c FREE 51b9 334736 bytes 9ff6 3087 000a*/ execlp("ps.exe", (char *) NULL); /* The output of ps.exe PID PPID SIZE DS Command 3087 258c 0728 3097 (sh.exe) c:/bin/sh.exe -R 0 <- my starting shell 37b0 FREE 003a 928 bytes 37eb FREE 0003 48 bytes 37ef 3087 02c0 39a1 (test.exe) c:/bin/ps.exe < the ps program overlayed 3ab0 FREE 6509 413840 bytes the test program 9fba 37ef 003a 9ff5 FREE 0000 0 bytes 9ff6 3087 000a*/ } Note in all cases the amount of free memory after the last process. This should answer all youe questions. -- Frank Kolakowski ====================================================================== |lfk@athena.mit.edu || Lee F. Kolakowski | |lfk@eastman2.mit.edu || M.I.T. | |kolakowski@wccf.mit.edu || Dept of Chemistry | |lfk@mbio.med.upenn.edu || Room 18-506 | |lfk@hx.lcs.mit.edu || 77 Massachusetts Ave.| |AT&T: 1-617-253-1866 || Cambridge, MA 02139 | |--------------------------------------------------------------------| | #include <woes.h> | | One-Liner Here! | ======================================================================