我需要与Linux的"cat /proc/uptime“完全相同的输出。
例如,使用/proc/uptime,您将获得
1884371.64 38646169.12
但是有了任何Mac的选择,比如“正常运行时间”,你就可以得到
20:25上升20:26,6个用户,平均负载: 3.19 2.82 2.76
我需要它是,就像 /proc/uptime,但是在Mac上。
发布于 2013-03-14 01:33:09
拿到了..。
$sysctl -n kern.boottime | cut -c14-18
87988然后,我将其转换为可读格式(不记得是如何实现的):
1天00:26:28
发布于 2013-03-11 01:00:20
Macintosh上根本没有"/proc“目录。
On MacOS, you can do a command like
sysctl kern.boottime 你会得到这样的回应:
kern.boottime: { sec = 1362633455, usec = 0 } Wed Mar 6 21:17:35 2013发布于 2013-07-18 19:28:58
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将返回大约1天,20小时,10分钟,55秒
https://stackoverflow.com/questions/15329443
复制相似问题