gpt4 book ai didi

c++ - timer_create() : -1 EAGAIN (Resource temporarily unavailable)

转载 作者:太空狗 更新时间:2023-10-29 20:30:03 24 4
gpt4 key购买 nike

我在运行 ARM 的嵌入式 Linux 下创建计时器时遇到了问题。我正在使用自制的 C++ 库来管理计时器。我没有自己编写代码,尽管我可以访问源代码,但我并不深入了解实现...它工作了一段时间,然后我收到错误“EAGAIN”。

使用 strace 我注意到当它不工作时定时器 ID 非常高!

timer_create(CLOCK_MONOTONIC, {0, SIGRT_3, SIGEV_SIGNAL, {...}}, 0xbed50af4) = -1 EAGAIN (Resource temporarily unavailable)

在工作时查看相当低的计时器 ID:

timer_create(CLOCK_MONOTONIC, {0x3, SIGRT_3, SIGEV_SIGNAL, {...}}, {0x3d}) = 0

我以为定时器的数量是无限的!其实并不是?我们应该在完成计时器后销毁它吗?我还使用了“timer_stats”内核实用程序,但这对我没有太大帮助......内核或任何其他工具中是否有其他用于定时器的调试实用程序?

感谢您的帮助!

最佳答案

您猜对了,您确实有最大数量的计时器:

   The kernel preallocates a "queued real-time signal" for each
timer created using timer_create(). Consequently, the number
of timers is limited by the RLIMIT_SIGPENDING resource limit
(see setrlimit(2)).

timer_create(3posix) 联机帮助页对此更为直白:

   The timer_create() function shall fail if:

EAGAIN The system lacks sufficient signal queuing resources
to honor the request.

EAGAIN The calling process has already created all of the
timers it is allowed by this implementation.

虽然您可以提高挂起信号的 setrlimit(2) 限制(bash(1) 中的 ulimit -i),但请注意这会分配真正的内核内存——这是一种极其有限的资源。

我建议修改您的应用程序以删除或重新使用旧计时器。

关于c++ - timer_create() : -1 EAGAIN (Resource temporarily unavailable),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8179427/

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