procfs question
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
Quoted 1 line · yenganti pradeep
length=sprintf(page,"Value %d",var++);
<snip>
Quoted 1 line
Why is this three numbers increment?
Ummm... because you are incrementing it? var++ means increment var.
Quoted 1 line · yenganti pradeep
Hi,
Hi,
Quoted 14 lines
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:
Quoted 7 lines
Value 0
Value 3
Value 6etc...
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...
Signature · 4 lines
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?