目录:/proc/uptime
//gcc
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE* pFile;
char str[64];
char str2[64];
double uptime=0, idle_time=0;
//从/proc/uptime读取系统的正常运行时间和累计空闲时间
pFile = fopen ("/proc/uptime", "r");
fscanf (pFile, "%s %s", str, str2); //string
printf("%-20s %-20s\n",str, str2);
rewind(pFile);
fscanf(pFile, "%lf %lf\n", &uptime, &idle_time); //double
printf("%-20lf %-20lf\n",uptime,idle_time);
fclose(pFile);
return 0;
}
//output:
48503.64 43260.32
48503.640000 43260.320000