【问题标题】:Is there way to get how much time was taken during the last boot of OS X?有没有办法获得在 OS X 的最后一次启动过程中花费了多少时间?
【发布时间】:2014-02-11 11:37:24
【问题描述】:

有没有办法以编程方式获取 OS X 的最后一次启动时间(目标 C/C)?例如,上次启动 OS X 需要 30 秒。

【问题讨论】:

标签: objective-c macos cocoa boot


【解决方案1】:

所以我不久前做了这个,让它显示在 Geek Tool 中。我最初希望在 Objective-C 中使用它,但结果证明它在 Python 中要容易得多:

import time
import subprocess
import re

currentTime = time.time()
p = subprocess.Popen('sysctl kern.boottime', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
    bootTime = line
    break

p = re.compile('\d+')
bootTime = p.findall(bootTime)[0]
uptime = int(currentTime) - int(bootTime)

不完全是你所追求的,但你可以从 Objective-C 调用这个脚本,或者如你所见,你调用的命令是 sysctl kern.boottime,它返回类似:kern.boottime: { sec = 1382617144, usec = 0 } Thu Oct 24 13:19:04 2013

【讨论】:

  • 你看过sysctl(3)吗?
  • 请重新阅读主题。我需要上次 OS X 启动过程花费了多少时间。 (不是上次启动的时间)。例如。上次 OS X 启动只用了 10 秒。
  • kern.boottime 没有这样的信息。
  • 你应该让你的问题更清楚。听起来您想知道自上次启动以来的时间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多