gpt4 book ai didi

java - 如何在 Java 中获得 UNIX 正常运行时间?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:37:38 25 4
gpt4 key购买 nike

在 Java 中获得 UNIX 正常运行时间的最佳方法是什么?有没有我可以使用的标准 Java 库/函数,或者我应该使用 Runtime 的 exec 或 ProcessBuilder 来执行“正常运行时间”?谢谢

最佳答案

你可以阅读/proc/uptime:

new Scanner(new FileInputStream("/proc/uptime")).next();
//"1128046.07" on my machine and still counting

来自 Wikipedia :

Shows how long the system has been on since it was last restarted:

$ cat /proc/uptime
350735.47 234388.90

The first number is the total number of seconds the system has been up. The second number is how much of that time the machine has spent idle, in seconds.

关于java - 如何在 Java 中获得 UNIX 正常运行时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8209096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com