请问关于读写proc文件问题
szclm 2005-12-26 07:56:23 我在内核中将一串信息写到/proc/info中:
static int share_read_proc_addr(char* buf, char ** start, off_t offset, int count, int* eof, void* data)
{
sprintf( buf, "%s\n","aaaaaaa:bbbbbbb:ccccccc" );
*eof = 1;
return 8*3;
}
在应用层读出这串信息:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp = NULL;
char szInfo[1024] = {0};
if ( (fp = fopen( "/proc/info", "r" )) == NULL )
{
printf( "open error!\n" );
return 0;
}
fread( szInfo, 24, 1, fp );
printf( "the info: %s\n", szInfo );
fclose( fp );
return 0;
}
但为什么打印出来的信息"有时"会是这样的:
NEEdddaaaaaaa:bbbbbbb:ccccccc
有时又是对的,常常在前面加了一些信息,这是为什么?!