-1

I want to find a way to find the linux system's uptime.

I do not want to read the uptime file in /proc/.

Any other way?

  • 1
    Please learn to search for an answer before posting. When I searched for `[linux] uptime` I found 488 answers, and third one was exactly what you have accepted below.As S.O. is about helping people fix their code (and not looking things up for them). please read http://stackoverflow.com/help/how-to-ask , http://stackoverflow.com/help/dont-ask , http://stackoverflow.com/help/mcve and take the [tour](http://stackoverflow.com/tour) before posting more Qs here. Thanks and Good luck. – shellter Feb 24 '17 at 19:07

1 Answers1

0
#include <stdio.h>
#include <sys/sysinfo.h>

int main(void)
{

    struct sysinfo sys_info;
    sysinfo(&sys_info);
    printf("Seconds since uptime: %lu\n", sys_info.uptime);

    return 0;
}

This should get you started. If you need more help, type man sysinfo into the terminal.