Skip to content
Advertisement

Uptime under linux in C

How can I retrieve uptime under linux using C? (without using popen and/or /proc)

Thanks

Advertisement

Answer

Via top or via uptime, but I don’t know about any syscall, someone will for sure 🙂

uptime should be rather easy to parse.

Just stumbled into this:

#include <sys/sysinfo.h>

struct sysinfo info;
sysinfo(&info);
printf("Uptime = %ldn", info.uptime);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement