How can I retrieve uptime under linux using C? (without using popen and/or /proc)
Thanks
Uptime Command In Linux: It is used to find out how long the system is active (running). This command returns set of values that involve, the current time, and the amount of time system is in running state, number of users currently logged into, and the load time for the past 1, 5 and 15 minutes respectively.
Right-click the Windows taskbar and select Task Manager. Once Task Manager is open, click the Performance tab. Under the Performance tab, you will find the label Uptime.
Just backup and replace /usr/bin/uptime with your own script which will show 100 days uptime. Show activity on this post. You can use UptimeFaker to change the machines up time for your testing.
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 = %ld\n", info.uptime);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With