读取proc/uptime信息。

时间:2020-12-11 23:28:10
 #include <stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include <memory.h>
int main()
{
int fd,size,FileLen = ,cur = ;
char s [ ]="Linux Programmer!",buffer[]; fd = open("/proc/uptime",O_RDONLY);
while(){
FileLen=lseek(fd,,SEEK_END);
lseek(fd,SEEK_SET,); while(size = read(fd,buffer,sizeof(buffer))){
cur +=size;
printf("%d---%s\n",size,buffer); memset(buffer,,sizeof(buffer));
if(cur>=FileLen){
cur = ;
break;
} } lseek(fd,SEEK_SET,);
sleep(); }
close(fd); }