All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: dash@vger.kernel.org, 595063@bugs.debian.org
Subject: Re: read() builtin doesnt read integer value /proc files (but bashs does)
Date: Wed, 15 Dec 2010 10:49:30 +0100 (CET)	[thread overview]
Message-ID: <1012151034250.15865@somehost> (raw)
In-Reply-To: <20101128084219.GC8818@gondor.apana.org.au>

On Sun, 28 Nov 2010, Herbert Xu wrote:
> On Sat, Sep 04, 2010 at 07:35:04PM +0000, Jilles Tjoelker wrote:
> >
> > > I attached an updated patch that corrects this pb by discarding the
> > > buffer when opening a new file.
> >
> > This discarding is still bad as it throws away valid data if the open
> > file description is shared. This happens if stdin is redirected inside a
>
> I'm with Jilles on this.  I also don't particularly feel like
> bloating dash just because of the borked /proc interface when
> there is a perfectly adequate work-around in "cat".
>
> 	value=$(cat /proc/file)

I wouldn't call that "a perfectly adequate work-around", but a painful and
unadequate work-around.  And this example will hopefully show why:

$ dash -c 'loops=10000; while [ $loops -gt 0 ];do read MAX
</proc/sys/kernel/pid_max; loops=$(($loops - 1)); done; times'
0m0.180000s 0m0.100000s
0m0.000000s 0m0.000000s

total: 0.28s

$ dash -c 'loops=10000; while [ $loops -gt 0 ];do MAX=$(cat
/proc/sys/kernel/pid_max); loops=$(($loops - 1)); done; times'
0m0.280000s 0m1.330000s
0m3.840000s 0m1.560000s

total: 7.01s

That is, the first example is 24x more efficient than the second.  And
that realy _matters_, I would say.


Cheers,

-- 
Cristian

  reply	other threads:[~2010-12-15  9:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-01  8:10 read() builtin doesn't read integer value /proc files (but bash's does) Steve Schnepp
2010-09-02 15:02 ` Steve Schnepp
2010-09-03 21:25   ` Jilles Tjoelker
2010-09-04 18:20     ` Steve Schnepp
2010-09-04 19:35       ` Jilles Tjoelker
2010-11-28  8:42         ` Herbert Xu
2010-12-15  9:49           ` Cristian Ionescu-Idbohrn [this message]
2010-12-15 18:55             ` read() builtin doesnt read integer value /proc files (but bashs does) Jonathan Nieder
2010-12-15 19:12               ` Cristian Ionescu-Idbohrn
2010-12-18 22:23               ` Jilles Tjoelker
2010-09-02 19:09 ` read() builtin doesn't read integer value /proc files (but bash's does) Jilles Tjoelker
2010-09-03  9:23   ` Steve Schnepp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1012151034250.15865@somehost \
    --to=cristian.ionescu-idbohrn@axis.com \
    --cc=595063@bugs.debian.org \
    --cc=dash@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.