From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 13 12:46:44 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DF9D916A468 for ; Wed, 13 Jun 2007 12:46:44 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from bunrab.catwhisker.org (adsl-63-193-123-122.dsl.snfc21.pacbell.net [63.193.123.122]) by mx1.freebsd.org (Postfix) with ESMTP id 6D4D513C487 for ; Wed, 13 Jun 2007 12:46:44 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from bunrab.catwhisker.org (localhost [127.0.0.1]) by bunrab.catwhisker.org (8.13.3/8.13.3) with ESMTP id l5DCWEC0002703; Wed, 13 Jun 2007 05:32:14 -0700 (PDT) (envelope-from david@bunrab.catwhisker.org) Received: (from david@localhost) by bunrab.catwhisker.org (8.13.3/8.13.1/Submit) id l5DCWDTc002702; Wed, 13 Jun 2007 05:32:13 -0700 (PDT) (envelope-from david) Date: Wed, 13 Jun 2007 05:32:13 -0700 From: David Wolfskill To: Garrett Cooper Message-ID: <20070613123213.GE98927@bunrab.catwhisker.org> References: <466F86C6.7010006@u.washington.edu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Rgf3q3z9SdmXC6oT" Content-Disposition: inline In-Reply-To: <466F86C6.7010006@u.washington.edu> User-Agent: Mutt/1.4.2.1i Cc: hackers@freebsd.org Subject: Re: Using shell commands versus C equivalents X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2007 12:46:45 -0000 --Rgf3q3z9SdmXC6oT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 12, 2007 at 10:55:18PM -0700, Garrett Cooper wrote: > Another simple question (I hope): > Is there any reason why shell commands should be used in place of a=20 > C command (in this case chmod via vsystem instead of the chmod(2)=20 > function)? It seems like the fork / exec would be more expensive with=20 > the shell command, but any area where code could be optimized is more=20 > than welcome I would think. There often are reasons to prefer using shell commands to C. There typically exist many tradeoffs involved in evaluating one over the other, and "machine efficiency" is not always the highest goal. (For example, it may be better to reduce complexity in favor of having a simpler structure that is easier for people to understand and maintain with confidence that the changes they make have the desired results. This is, of course, not to try to claim that shell scripts are inherently easier to understand than C code; that would be a silly stance to take.) I commend to your attention Geoff Collyer and Henry Spencer's "C News" (a successor to Rick Adams' "B News") implementation, a great deal of which was written as shell scripts (ca. 1988 or so). (Yes, I realize that that was almost 20 years ago, and that it didn't involve FreeBSD per se. Ignoring the lessons of history is rather short-sighted and foolish: despite using shell scripts for so much of the "code," the machine I was then running went from being extremely busy all the time to having a couple of bursts of activity per day for about an hour each time -- with more news flowing with C News vs. B News.) Peace, david --=20 David H. Wolfskill david@catwhisker.org Anything and everything is a (potential) cat toy. See http://www.catwhisker.org/~david/publickey.gpg for my public key. --Rgf3q3z9SdmXC6oT Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (FreeBSD) iEYEARECAAYFAkZv48wACgkQmprOCmdXAD2WDQCfUvmm3BFmpRypqnatSeHoMl17 BjsAnRY7KXZuDJ/xAedy5Xs8LR4bSQqG =CKZ9 -----END PGP SIGNATURE----- --Rgf3q3z9SdmXC6oT--