OSX: programmatically get uptime?

Mark Harrison picture Mark Harrison · Jul 17, 2010 · Viewed 9.1k times · Source

Something similar to linux

cat /proc/uptime

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

Answer

Shaggy Frog picture Shaggy Frog · Jul 17, 2010

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).