From owner-freebsd-questions Thu Apr 25 13:30:44 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mailgw3a.lmco.com (mailgw3a.lmco.com [192.35.35.24]) by hub.freebsd.org (Postfix) with ESMTP id 7D75637B416 for ; Thu, 25 Apr 2002 13:30:36 -0700 (PDT) Received: from emss04g01.ems.lmco.com ([166.17.13.122]) by mailgw3a.lmco.com (8.11.6/8.11.6) with ESMTP id g3PKUZ229893; Thu, 25 Apr 2002 16:30:35 -0400 (EDT) Received: from CONVERSION-DAEMON by lmco.com (PMDF V5.2-33 #40649) id <0GV500F014YG6C@lmco.com>; Thu, 25 Apr 2002 16:30:35 -0400 (EDT) Received: from emss04i00.ems.lmco.com ([166.17.13.135]) by lmco.com (PMDF V5.2-33 #40649) with ESMTP id <0GV50036O4Y8OU@lmco.com>; Thu, 25 Apr 2002 16:30:08 -0400 (EDT) Received: by emss04i00.ems.lmco.com with Internet Mail Service (5.5.2653.19) id ; Thu, 25 Apr 2002 16:30:08 -0400 Content-return: allowed Date: Thu, 25 Apr 2002 16:30:07 -0400 From: "Kohler, Raymond J" Subject: RE: what are parent and child processes all about? To: "'Bsd Neophyte'" , freebsd-questions@FreeBSD.ORG Message-id: MIME-version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG -----Original Message----- From: Bsd Neophyte [mailto:bsdneophyte@yahoo.com] Sent: Thursday, April 25, 2002 4:16 PM To: freebsd-questions@FreeBSD.ORG Subject: what are parent and child processes all about? >"When a process is started, a duplicate of that process is created. This >new process is called the child and the process that created it is called >the parent. The child process then replaces the copy for the code the >parent process created with the code the child process is supposted to >execute." So you have a program running, the shell you type things at (the parent). It wants to run the program you typed. So what it does is to clone itself (that's the fork() system call), and the clone (the child) then transmutes itself into the program to be run (the exec() call). That's the code copy you're reading about here. That is, your shell can't run somthing else without destroying itself, so it forks another of itself and lets that destroy itself instead. >The last sentance confuses me the most. Actually the entire thing >confsues me. Why is a child process started anyways? Why does the parent >process spawn a child process in the first place? And what's all this >code copy stuff all about? A program can't "start another program". It can only "clone itself" or "transmute itself". So starting another program is a combination of these. >"While the command is executing, the shell waits until the child process >has completed. After is completes, the parent process terminates the >child process, and a prompt is displated, ready for a new command" >Why does this happen? I guess it goes back to my confusion about why the >child process is created in the first place. The shell just wants to wait for the first command to finish before doing another one. Otherwise things could get a bit muddled up (I'm oversimplifying here). -- Ray To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message