public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* procfs question
@ 2006-03-28 15:34 yenganti pradeep
  2006-03-28 16:15 ` Phillip Susi
  2006-03-28 16:27 ` Paulo Marques
  0 siblings, 2 replies; 3+ messages in thread
From: yenganti pradeep @ 2006-03-28 15:34 UTC (permalink / raw)
  To: linux-kernel


Hi,

I've created a new entry under /proc, to make tests.

I've defined an static int var=0;

Then I link my proc entry read function to a function
that only performs this:

int length;
length=sprintf(page,"Value %d",var++);

return length;

But when I cat/vi the file continuosly I get:

Value 0
Value 3
Value 6

etc...

Why is this three numbers increment? 

Thanks
Pradeep





		
__________________________________________________________ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: procfs question
  2006-03-28 15:34 procfs question yenganti pradeep
@ 2006-03-28 16:15 ` Phillip Susi
  2006-03-28 16:27 ` Paulo Marques
  1 sibling, 0 replies; 3+ messages in thread
From: Phillip Susi @ 2006-03-28 16:15 UTC (permalink / raw)
  To: yenganti pradeep; +Cc: linux-kernel

yenganti pradeep wrote:
> length=sprintf(page,"Value %d",var++);
<snip>
> Why is this three numbers increment? 

Ummm... because you are incrementing it?  var++ means increment var.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: procfs question
  2006-03-28 15:34 procfs question yenganti pradeep
  2006-03-28 16:15 ` Phillip Susi
@ 2006-03-28 16:27 ` Paulo Marques
  1 sibling, 0 replies; 3+ messages in thread
From: Paulo Marques @ 2006-03-28 16:27 UTC (permalink / raw)
  To: yenganti pradeep; +Cc: linux-kernel

yenganti pradeep wrote:
> Hi,

Hi,

> I've created a new entry under /proc, to make tests.
> 
> I've defined an static int var=0;
> 
> Then I link my proc entry read function to a function
> that only performs this:
> 
> int length;
> length=sprintf(page,"Value %d",var++);
> 
> return length;
> 
> But when I cat/vi the file continuosly I get:
> 
> Value 0
> Value 3
> Value 6
> 
> etc...
> 
> Why is this three numbers increment? 

'cat' will issue a read for more bytes than your function provides. As 
this read isn't fully satisfied it will issue another read for the rest 
at a different offset, etc. So your function gets called several times.

Just do a 'strace' on 'cat' to see what 'cat' really does. For more 
details search for the thread 'procfs uglyness caused by "cat"'.

Your read function really shouldn't have side effects...

-- 
Paulo Marques - www.grupopie.com

Pointy-Haired Boss: I don't see anything that could stand in our way.
            Dilbert: Sanity? Reality? The laws of physics?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-03-28 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-28 15:34 procfs question yenganti pradeep
2006-03-28 16:15 ` Phillip Susi
2006-03-28 16:27 ` Paulo Marques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox