I would like to get the system uptime from within a C application running on a linux-based system. I don\'t want to call uptime(1) and parse the output, I\'d like to call t
That would be something like this.
#include
#include
#include /* for _syscallX macros/related stuff */
#include /* for struct sysinfo */
#include
long get_uptime()
{
struct sysinfo s_info;
int error = sysinfo(&s_info);
if(error != 0)
{
printf("code error = %d\n", error);
}
return s_info.uptime;
}
See "man sysinfo" for more info.