Linux在C中的正常运行时间 [英] Uptime under linux in C

查看:103
本文介绍了Linux在C中的正常运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux下使用C检索正常运行时间? (不使用popen和/或/proc)

How can I retrieve uptime under linux using C? (without using popen and/or /proc)

谢谢

推荐答案

通过top或通过uptime,但是我不知道任何系统调用,肯定会有人:)

Via top or via uptime, but I don't know about any syscall, someone will for sure :)

uptime应该很容易解析.

只是偶然发现:

#include <sys/sysinfo.h>

struct sysinfo info;
sysinfo(&info);
printf("Uptime = %ld\n", info.uptime);

这篇关于Linux在C中的正常运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆