Subject: Re: ksh bugs and behaviour questions
To: None <>
From: James K. Lowden <>
List: tech-userlevel
Date: 01/26/2003 14:21:41
On Sat, 25 Jan 2003 16:00:24 -0500, Roland Dowdeswell <>
> David Laight wrote:
> >I'm surpised there is that much difference!
> >Trully odd things must be going on in ksh (I don't have bash).
> Well, yes and no.  We just hacked /bin/sh to use vfork(2) rather
> than fork(2) based on this speedup.  So, ksh which still uses
> fork(2) is going to be a lot slower.

I should mention my test was on NetBSD 1.4.2, definitely from the
pre-vfork era.  A 1.6 Sparcstation yields very different results (with
apologies to Matthias):

$ time sh -c 'for i in $(jot 10000); do /bin/echo -n; done' 
real    1m23.455s
user    0m2.387s
sys     0m19.027s

$ time ksh -c 'for i in $(jot 10000); do /bin/echo -n; done'
real    2m0.303s
user    0m6.465s
sys     0m34.900s

$ time bash -c 'for i in $(jot 10000); do /bin/echo -n; done'
real    2m31.771s
user    0m13.990s
sys     0m47.395s

My instinct is to agree with Matthias, that fork & exec don't amount to
much in the great scheme of things.  But my head says no, there are many
interpretations.  Here's 10,000 invocations taking bash 28 extra seconds
of CPU time.  That only 1000 execs for 10 users.  

Well, I hope I'm not beating a dead horse.  Like David, I was surprised to
find so much difference in what I would have thought is a trivial, well
understood process.