简体   繁体   English

时间()系统调用。 溢出的返回值

[英]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.

相关问题 Linux futex系统调用虚假唤醒,返回值为0? - Linux futex syscall spurious wakes with return value 0? Linux C中的时间返回值0 - Times return value 0 in Linux C Linux中“ times”系统调用的返回值是多少 - What is the return value of “times” system call in linux 读取系统调用返回垃圾并读取比写入系统调用在套接字中写入的次数更多 - read syscall returns trash and reads more times than write syscall writes in a socket 为什么Linux系统调用返回类型为“long”? - Why is Linux syscall return type “long”? Linux内核syscall返回未给定指针 - Linux kernel syscall return not given pointer 使用相同的输入多次调用函数,但获得不同的返回值 - Call a function multiple times with the same input but get different return value 为什么在C中将较大的double转换为long有时返回正数,而其他时候返回负数? - Why does casting a large double to a long sometimes return a positive and other times return a negative value in C? 为什么在单个printf中多次调用函数时,函数仅返回一个值? - Why does function return only one value when called multiple times in a single printf? 为什么整数数组大小(数组)的返回值只是元素数的4倍? - Why is the return value of integer array size(array) just 4 times the number of elements?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM