【发布时间】:2013-12-30 00:39:46
【问题描述】:
如何以编程方式获取 OS X 中上次系统启动/重启的持续时间?
我只需要知道我的 OS X 重启速度有多快。
【问题讨论】:
标签: objective-c c macos boot
如何以编程方式获取 OS X 中上次系统启动/重启的持续时间?
我只需要知道我的 OS X 重启速度有多快。
【问题讨论】:
标签: objective-c c macos boot
以下代码(来源于https://stackoverflow.com/a/14345786/1187415中的代码) 打印上次重启的时间:
#include <stdio.h>
#include <utmpx.h>
int main(int argc, const char * argv[])
{
struct utmpx *bp;
char *ct;
setutxent_wtmp(0); // 0 = reverse chronological order
while ((bp = getutxent_wtmp()) != NULL) {
if (bp->ut_type == BOOT_TIME) {
ct = ctime(&bp->ut_tv.tv_sec);
printf("last reboot: %s", ct);
break;
}
};
endutxent_wtmp();
return 0;
}
输出与命令行中“last reboot”的第一行相同。
【讨论】: