在类Unix系统上以秒或毫秒为单位获取正常运行时间

编程入门 行业动态 更新时间:2024-10-28 06:25:29
本文介绍了在类Unix系统上以秒或毫秒为单位获取正常运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要一个方法,它可以给我从系统启动以来经过的毫秒数或秒数。 我可以解析 / proc / uptime ,但我不能失去在这个I / 0和解析的性能。

I need a method which can give me the number of miliseconds or seconds, elapsed since the system was started. I could parse /proc/uptime , but i can't afford to lose performance over this I/0 and parsing.

我使用Linux和C / C ++。

I'm using Linux and C/C++. Maybe i can put some Qt/Boost, but is better to be something native.

推荐答案

为什么你不能读懂 / proc / uptime ?它不是真正的文件,所以读取它应该是快速的(没有真正的i / o涉及,因为 / proc / 文件系统包含伪文件)。

Why cannot you afford reading /proc/uptime? It is not a real file so reading it should be quick (there is no real i/o involved, since the /proc/ filesystem contains pseudo-files). Did you benchmark its reading?

您也可以拨打 clock_gettime a>与 CLOCK_MONOTONIC

You might also call clock_gettime with CLOCK_MONOTONIC

NB。这是特定于Linux的。

NB. This is specific to Linux.

更多推荐

在类Unix系统上以秒或毫秒为单位获取正常运行时间

本文发布于:2023-10-08 13:46:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472809.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正常运行   上以   单位   时间   系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!