gpt4 book ai didi

c - 使用 ualarm 的问题

转载 作者:太空宇宙 更新时间:2023-11-04 07:00:14 25 4
gpt4 key购买 nike

在我的代码中,我需要在 2 秒后调用 sigalrm。但是,当我使用 ualarm(2000000, 0 ) 时,它不起作用。使用 ualarm 不到 1 秒就可以了。而 alarm(2) 有效。为什么 ualarm 有时应该在 alarm 上使用?有没有办法让 ualarm 工作超过 1 秒?

最佳答案

ualarm() 已过时,实际上已从 POSIX 中删除。不要使用它。

如果您仍然坚持使用它,Linux 手册页会注明:

The type useconds_t is an unsigned integer type capable of holding integers in the range [0,1000000].

,我猜这是对一次性 POSIX 规范的引用。你应该从中得到的是,POSIX ualarm() 从未保证能够处理大于 1000000 的第一个参数。目前还不清楚是否有任何实现处理过更大的值,但 POSIX指定它,因为它表明至少有些实现没有。

Is there any way to get ualarm to work for over 1 second?

由于(不再)没有任何ualarm() 的标准,答案必然取决于实现。根据您介绍的内容,我倾向于认为通过您的实现,答案是否定的。

关于c - 使用 ualarm 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39621838/

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