#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <linux/kernel.h>
static unsigned long print_uptime(void)
{int fd = -1;
int size = 0;
int i = 0;
unsigned long second = 0;
char tmpBuf[100];
char buffer[100];
fd = open("/proc/uptime", O_RDONLY);
if(-1 == fd)
{
return -1;
}
size = read(fd, tmpBuf, sizeof(tmpBuf));
close(fd);
while(tmpBuf[i] != '.')
{
buffer[i] = tmpBuf[i];
i++;
}
buffer[i] = '\0';
second = atol(buffer);
printf("Machine run time seconds : %ld \n", second);
return second;
}
void main(void)
{
print_uptime();
}