From owner-freebsd-current Tue Jul 3 22:47:48 2001 Delivered-To: freebsd-current@freebsd.org Received: from mailgate.novagate.net (mailgate.novagate.net [205.138.138.22]) by hub.freebsd.org (Postfix) with ESMTP id 67F9337B403 for ; Tue, 3 Jul 2001 22:47:45 -0700 (PDT) (envelope-from djhill@novagate.net) Received: from rain.hill.hom (081bc122.chartermi.net [24.247.81.122]) by mailgate.novagate.net (8.11.3/8.11.3) with SMTP id f645ldq56390 for ; Wed, 4 Jul 2001 01:47:39 -0400 (EDT) (envelope-from djhill@novagate.net) Date: Wed, 4 Jul 2001 01:47:03 -0400 From: David Hill To: freebsd-current@freebsd.org Subject: system and (v)fork Message-Id: <20010704014703.4ec62b5f.djhill@novagate.net> X-Mailer: Sylpheed version 0.5.0pre2 (GTK+ 1.2.10; i386-unknown-freebsd4.3) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hello - Reading Advanced Programming in the UNIX Environment by Richard W. Stevens, I see that he says that vfork() should be used instead of fork() when you just need to use one of the exec() functions, since it doesn't need to fully copy the address space. Later in the book, he has an example system() which uses fork() to run /bin/sh -c via the execl() function. Why wouldn't he use vfork() instead of fork()? I ran FreeBSD's version of system() both by the default (using fork()) and by using vfork() I ran a loop 1000 times that called system("echo"); Here are my results: time ./app fork() vfork() 1. 4.528 3.056 0.050 0.058 2.078 1.492 2. 3.652 2.865 0.060 0.060 2.036 1.484 3. 3.735 3.022 0.068 0.041 2.031 1.506 As you can see, vfork() performed better. But, I am sure there is good reasoning for using fork() over vfork() in the system() call, and I am just curious why. Can anyone explain this? Thanks - David To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message