第五个位置是什么操作系统时间返回值到底是什么意思?

2024-09-28 23:29:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道pythonos.times()函数将返回一个5位元组,前四位是(我认为)不同的处理器时间度量。你知道吗

然而,这个函数有一点让我困惑。第五个位置是什么?从过去的某个固定点开始经过的时间?从那以后?这是用来测量挂钟时间的吗?这就是文档中所说的“(处理器或其他)时间”的含义吗?你知道吗


Tags: 函数文档度量时间处理器元组times含义
1条回答
网友
1楼 · 发布于 2024-09-28 23:29:13

所有的时间都是相对于一个固定点的;这取决于操作系统来选择该点,甚至在同一操作系统的不同版本之间也是不同的。你知道吗

参见^{} documentation

On Linux, the "arbitrary point in the past" from which the return value of times() is measured has varied across kernel versions. On Linux 2.4 and earlier this point is the moment the system was booted. Since Linux 2.6, this point is (2^32/HZ) - 300 (i.e., about 429 million) seconds before system boot time. This variability across kernel versions (and across UNIX implementations), combined with the fact that the returned value may overflow the range of clock_t, means that a portable application would be wise to avoid using this value. To measure changes in elapsed time, use clock_gettime(2) instead.

Python从clock_t结构返回tms_utimetms_stimetms_cutimetms_cstime字段,其中第5个值是times()调用本身的返回值,因此过去从任意点开始经过的时钟滴答数。它已经将这些值从时钟信号转换为表示秒的浮点值。你知道吗

第五个值只会告诉你,在过去,以秒为单位,这个任意点在挂钟时间内有多远(或者尽可能接近操作系统测量的时间)。你知道吗

相关问题 更多 >