Luna/apps/src/uptime.c

27 lines
397 B
C
Raw Normal View History

#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);
if (ferror(fp))
{
2022-10-22 12:23:34 +00:00
perror("fgets");
return 1;
}
long ms_uptime = atol(buf);
printf("up for %ld seconds\n", ms_uptime / 1000);
fclose(fp);
}