tags:

views:

69

answers:

3

Something similar to linux

cat /proc/uptime

which returns the uptime in seconds, and preferably not parsing uptime(1).

+6  A: 

The Uptime article on Wikipedia has an interesting lead:

Using sysctl

There is also a method of using sysctl to call the system's last boot time: $ sysctl kern.boottime kern.boottime: { sec = 1271934886, usec = 667779 } Thu Apr 22 12:14:46 2010

Which references sysctl(8), which references sysctl(3).

Shaggy Frog
Thanks, this is just what I need
Mark Harrison
and just in case any apple people see this, it sure would be nice to have this wrapped up in /proc!!
Mark Harrison
A: 

There is a function UpTime declared in DriverServices.h. I believe this is equivalent to another function mach_absolute_time. Both seem to be undocumented.

JWWalker
A: 

Unfortunately the "sysctl kern.boottime" returns the seconds of the timestamp, not elapsed seconds.. Multiple calls do not increase the second count, but must be seconds from epoc of the boot date itself.

Uri
Just subtract the system's boot time from the current time to find out how long the system has been up.
Gabe