Now I'm really confused. =)
This prg works on both FOX and a PC machine:
#include <stdio.h>
#include <fcntl.h>
void main(void)
{
int fil;
char c;
int i = 0;
while(1)
{
fil = open("/proc/diskstats", O_RDONLY);
if(fil < 0) printf("Open error!");
if(read(fil, &c, 1) <= 0) printf("Read error!");
close(fil);
i++;
printf("%d\n", i);
}
}
...and the other test program I wrote don't work on the FOX OR PC machine. So
at least it's consistent. =)
Does it have anything to do with opening the file in a function...? No, it
can't, can it....? Or am I just blind not seeing the error? =)
Best regards, Jonas
--- In [email protected], j...@... wrote:
>
> on proc you should use open() close() read()
>
> please post the complete code
>
>
>
>
> Quoting "jonas.elofsson" <jelofs...@...>:
>
> > Hi!
> >
> > I have a problem reading files in the /proc directory in C.
> >
> > I made a module for reading SMARTTEMP temperature sensors, and it
> > works great. I made it to create one file for each I/O pin under
> > /proc/smarttemp/. Working beautifully.
> >
> > I also made a module for controlling my LCD display, and that to
> > works like a charm.
> >
> > I put together a small test program to read 8 different temperaturs
> > from different sensors and then display them on the display updating
> > once every second.
> >
> > Works great, for two minutes...
> >
> > Then, when one of the /proc files is read for the 1024:th time
> > problems occurs. It turns out the file descriptors are out..! They
> > don't seem to get relesaed when I do a fclose (I use fopen and
> > fclose on them, is this a problem?).
> >
> > I get no problems if I change the program to read from a file on the
> > normal FS instead.
> >
> > If I try to read some other file in /proc i get the same error after
> > 1024 loops... So it seems it's not in my driver code.
> >
> > I tried to do a system("cp /proc/smarrtemp/PG01 /var/temp"); for
> > each measurement and then reading the file in /var instead, trying
> > to fool it a bit, just for testing. But after about 1024 copies I
> > still get problems.
> >
> > I would be very thankful for any ideas about why this is and how to
> > get it working.
> >
> > I use the image on ACMEs homepage, 2.6 something. =)
> >
> > Best regards, Jonas
> >
> >
> >
> >
>
>
>
> --
> John Crispin
> hacking, coding, etc
> blogic on irc
>
> _______ ________ __
> | |.-----.-----.-----.| | | |.----.| |_
> | - || _ | -__| || | | || _|| _|
> |_______|| __|_____|__|__||________||__| |____|
> |__| W I R E L E S S F R E E D O M
> KAMIKAZE (bleeding edge) -----------------------
> * 10 oz Vodka Shake well with ice and strain
> * 10 oz Triple sec mixture into 10 shot glasses.
> * 10 oz lime juice Salute!
> ---------------------------------------------------
>