Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uptime under linux in C

Tags:

c

linux

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

Thanks

like image 632
drizzt Avatar asked Jun 18 '10 14:06

drizzt


People also ask

What is uptime command Linux?

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.

How do I view uptime?

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.

How do I change uptime in Linux?

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.


1 Answers

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);
like image 195
Jack Avatar answered Oct 26 '22 23:10

Jack