/ proc / uptime on Mac OS X

I need EXACTLY the same output as Linux "cat / proc / uptime".

For example, using / proc / uptime you will get

1884371.64 38646169.12

but with any Mac alternative, such as uptime, you’ll get

20:25 to 20:26, 6 users, weighted average loads: 3.19 2.82 2.76

I need it to be exactly like cat / proc / uptime, but on Mac OS X.

+6
source share
3 answers

Got it ...

$sysctl -n kern.boottime | cut -c14-18 87988 

Then I just converted this to a readable format (I don’t remember how):

1 day 00:26:28

+6
source

Macintosh simply does not have a / proc directory.

On MacOS, you can run a command, for example :

 sysctl kern.boottime 

and you will get an answer like:

 kern.boottime: { sec = 1362633455, usec = 0 } Wed Mar 6 21:17:35 2013 
+3
source
 boottime=`sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//g'` unixtime=`date +%s` timeAgo=$(($unixtime - $boottime)) uptime=`awk -v time=$timeAgo 'BEGIN { seconds = time % 60; minutes = int(time / 60 % 60); hours = int(time / 60 / 60 % 24); days = int(time / 60 / 60 / 24); printf("%.0f days, %.0f hours, %.0f minutes, %.0f seconds", days, hours, minutes, seconds); exit }'` echo $uptime 

Will return something like 1 day, 20 hours, 10 minutes, 55 seconds.

-1
source

All Articles