我如何获得Linux系统的正常运行?

问题描述:

我想找到一种方法来查找linux系统的正常运行时间。我如何获得Linux系统的正常运行?

我不想读取/proc/中的运行时间文件。

还有其他方法吗?

+1

请在发帖前了解搜索答案。当我搜索'[linux]正常运行时间'时,我发现了488个答案,而第三个答案正是你在下面接受的内容。是关于帮助人们修复他们的代码(而不是为他们寻找)。请阅读http://*.com/help/how-to-ask,http://*.com/help/dont-ask,http://*.com/help/mcve并参加[tour]( http://*.com/tour)在发布更多Q​​之前。谢谢,祝你好运。 – shellter

#include <stdio.h> 
#include <sys/sysinfo.h> 

int main(void) 
{ 

    struct sysinfo sys_info; 
    sysinfo(&sys_info); 
    printf("Seconds since uptime: %lu\n", sys_info.uptime); 

    return 0; 
} 

这应该让你开始。如果您需要更多帮助,请在终端中键入man sysinfo