首页 > 代码库 > 读取proc/uptime信息。

读取proc/uptime信息。

 1 #include <stdio.h>
 2 #include<unistd.h> 
 3 #include<sys/types.h> 
 4 #include<sys/stat.h> 
 5 #include<fcntl.h> 
 6 #include <memory.h>
 7 int main() 
 8 { 
 9 int fd,size,FileLen = 0,cur = 0; 
10 char s [ ]="Linux Programmer!",buffer[100]; 
11 
12 fd = open("/proc/uptime",O_RDONLY);
13 while(1){
14     FileLen=lseek(fd,0,SEEK_END);
15     lseek(fd,SEEK_SET,0);
16 
17 while(size = read(fd,buffer,sizeof(buffer))){
18     cur +=size;
19     printf("%d---%s\n",size,buffer);
20     
21     memset(buffer,0,sizeof(buffer));
22     if(cur>=FileLen){
23         cur = 0;
24         break;    
25     }
26 
27 }
28 
29 lseek(fd,SEEK_SET,0);
30 sleep(1);
31 
32 }
33 close(fd); 
34 
35 }

 

读取proc/uptime信息。