27 lines
397 B
C
27 lines
397 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main()
|
|
{
|
|
FILE* fp = fopen("/dev/uptime", "r");
|
|
if (!fp)
|
|
{
|
|
perror("fopen");
|
|
return 1;
|
|
}
|
|
|
|
char buf[32];
|
|
fgets(buf, sizeof(buf), fp);
|
|
|
|
if (ferror(fp))
|
|
{
|
|
perror("fgets");
|
|
return 1;
|
|
}
|
|
|
|
long ms_uptime = atol(buf);
|
|
|
|
printf("up for %ld seconds\n", ms_uptime / 1000);
|
|
|
|
fclose(fp);
|
|
} |