[英]times() syscall. Overflowed return value
Which value will be returned if possible clock_t (aka signed long) range will be overflowed?如果可能的clock_t(又名有符号长)范围溢出,将返回哪个值?
Let's assume that I use kernel 2.6 version and arch is x86 (32 bits).假设我使用内核 2.6 版本并且 arch 是 x86(32 位)。 sizeof(signed long) = 4 bytes.
sizeof(signed long) = 4 字节。 Max value = 2147483647.
最大值 = 2147483647。
According to man page - here , syscall times() returns the number of clock ticks that have elapsed since an arbitrary point in the past.根据手册页 - here , syscall times()返回自过去任意点以来已经过去的时钟滴答数。
In "Notes" section mentioned following: "On Linux, the "arbitrary point in the past" from which the return value of times() is measured has varied across kernel versions. Since Linux 2.6, this point is (2^32/HZ) - 300 seconds before system boot time" .在“注释”部分中提到了以下内容: “在 Linux 上,测量 times() 返回值的“过去的任意点”因内核版本而异。从 Linux 2.6 开始,该点是 (2^32/HZ ) - 系统启动时间前 300 秒” 。
So, I don't understand what value in decimal representation will be start point (suppose HZ = 100).所以,我不明白十进制表示中的什么值将是起点(假设 HZ = 100)。 And what return value will be after overflowing.
溢出后返回值是什么。
As I cannot yet comment I hope this answer is of some use.. according to this man由于我还不能发表评论,我希望这个答案有一些用处..根据这个人的说法
times() returns the number of clock ticks that have elapsed since an arbitrary point in the past.
times() 返回自过去任意点以来经过的时钟滴答数。 The return value may overflow the possible range of type clock_t.
返回值可能会溢出clock_t 类型的可能范围。 On error, (clock_t) -1 is returned, and errno is set appropriately.
出错时,返回 (clock_t) -1,并适当设置 errno。
so it can overflow, yes, and when it does it will go from +2,147,483,647 to −2,147,483,647 if the return is an unsigned long and continue to tick in positive direction.所以它可以溢出,是的,当它溢出时,它会从+2,147,483,647变为-2,147,483,647,如果返回是unsigned long并继续向正方向滴答。 However signed integers are undefined after overflow, this is due to compilers handling them differently for optimization, here .
然而,溢出后有符号整数是未定义的,这是由于编译器对它们的优化处理方式不同, 这里。
If my assumption is correct it can overflow multiple times meaning your value could be invalid after overflow if unsigned or the value will be undefined (random) if signed .如果我的假设是正确的,它可能会溢出多次,这意味着如果unsigned溢出后您的值可能无效,或者如果signed值将是 undefined (随机) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.