2022-10-19 19:11:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
FILE* fp = fopen("/dev/uptime", "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
perror("fopen");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-10-22 12:23:34 +00:00
|
|
|
char buf[32];
|
|
|
|
fgets(buf, sizeof(buf), fp);
|
2022-10-19 19:11:38 +00:00
|
|
|
|
|
|
|
if (ferror(fp))
|
|
|
|
{
|
2022-10-22 12:23:34 +00:00
|
|
|
perror("fgets");
|
2022-10-19 19:11:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
long ms_uptime = atol(buf);
|
|
|
|
|
|
|
|
printf("up for %ld seconds\n", ms_uptime / 1000);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|