All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul Rolland" <rol@witbe.net>
To: "'Robert Hancock'" <hancockr@shaw.ca>,
	"'Herbert Rosmanith'" <kernel@wildsau.enemy.org>
Cc: "'linux-kernel'" <linux-kernel@vger.kernel.org>
Subject: Re: procfs uglyness caused by "cat"
Date: Tue, 14 Mar 2006 16:33:28 +0100	[thread overview]
Message-ID: <001901c6477c$a46b4c90$b600a8c0@cortex> (raw)
In-Reply-To: <4416D4A3.9070705@shaw.ca>

> > static int uptime_read_proc(char *page, char **start, off_t off,
> >                                  int count, int *eof, void *data)
> > {
> >         struct timespec uptime;
> >         struct timespec idle;
> >         int len;
> >         cputime_t idletime;
> > 
> > +	if (off)
> > +		return 0;
> 
> Except that this is wrong - if you try to advance the offset 
> a bit from 
> the start of the file and read something, you'll get nothing. This is 
> inconsistent with normal file behavior.

Right... What's weird is : what do we get if a process decides to read
this using a 1 byte buffer, asking for 1 char at a time ?
And what we'll be the result if you read 1 char every 1 second ?

#include <stdio.h>

int main(int argc, char * argv[])
{
  FILE * f;
  char lChar;

  f = fopen("/proc/uptime", "r");
  if (f == NULL) {
    exit(0);
  } /* endif */

  while (!feof(f)) {
    fread(&lChar, 1, 1, f);
    fprintf(stdout, "%c", lChar); fflush(stdout);
    sleep(1);
  } /* endwhile */

  close(f);

  exit(0);
}

is funny enough...

2.2.x :
58 [15:30] rol@www-dev:/tmp> cat /proc/uptime ; ./test
13849305.25 13555633.92
13849312.38 13555635.64

2.4.31 :
bash-2.05# cat /proc/uptime ; ./test
100711.77 100366.30
100711.77 100366.30

Paul


  reply	other threads:[~2006-03-14 15:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5Qfgo-3At-15@gated-at.bofh.it>
2006-03-14 14:35 ` procfs uglyness caused by "cat" Robert Hancock
2006-03-14 15:33   ` Paul Rolland [this message]
2006-03-14 17:59     ` Paul Jackson
2006-03-14 18:45       ` Paul Rolland
2006-03-15  8:06   ` Herbert Rosmanith
2006-03-15  8:23   ` Herbert Rosmanith
2006-03-14 10:43 Herbert Rosmanith
2006-03-14 15:57 ` Paul Jackson

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='001901c6477c$a46b4c90$b600a8c0@cortex' \
    --to=rol@witbe.net \
    --cc=hancockr@shaw.ca \
    --cc=kernel@wildsau.enemy.org \
    --cc=linux-kernel@vger.kernel.org \
    /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.