Path: utzoo!utgpu!water!watmath!clyde!cbosgd!cbdkc1!pmd From: pmd@cbdkc1.ATT.COM (Paul Dubuc) Newsgroups: comp.lang.c Subject: Re: system Keywords: c program Message-ID: <2788@cbdkc1.ATT.COM> Date: 22 Jan 88 14:42:43 GMT References: <127@dcrbg1.UUCP> <452@picuxa.UUCP> <3920@sigi.Colorado.EDU> Reply-To: pmd@cbdkc1.UUCP (Paul Dubuc) Organization: AT&T Bell Laboratories; Columbus, Ohio Lines: 26 In article <3920@sigi.Colorado.EDU> swarbric@tramp.Colorado.EDU (SWARBRICK FRANCIS JOHN) writes: }In article <452@picuxa.UUCP> gp@picuxa.UUCP (Greg Pasquariello X1190) writes: }> if(!fork()) }> execlp("/bin/sh","sh","-c",command,0); }> wait() } }Just curious, but what do fork() and wait() do? I have Turbo C, and it has }execlp(), but neither of the other two. Does it have something to do with }the fact that UNIX is multiuser, while MS-DOS is not? Close. It has to do with UNIX being multiprocessing. On UNIX, fork() clones the process into two virtually identical processes. execlp() overlays the currently running process with the one specified by the arguments. Wait() waits for a "child" process to terminate. Although it's not very clear in this example, only the child process does the execlp(), the parent executes the wait() which returns when the child terminates. (Fork() returns 0 to the child; the process ID of the child (a positive integer) to the parent). The execlp() in Turbo C probably acts similarly to system() on UNIX. It stops the calling program, runs the subprogram, and resumes the calling program when that's done. In UNIX a parent process does not have to wait for the subprocess (child) to finish before continuing. -- Paul Dubuc {ihnp4,cbosgd}!cbdkc1!pmd