C等待时间或用SIGWAIT发信号 [英] C wait for time or signal with sigwait

查看:0
本文介绍了C等待时间或用SIGWAIT发信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要等待X秒或信号到达时。

我可以使用sigwait,但它只监听信号,没有超时。

正确的方法是什么?

推荐答案

可以使用sigtimedwait()函数,该函数在作为参数给定的超时后返回。
以下是文档:http://www2.phys.canterbury.ac.nz/dept/docs/manuals/unix/DEC_4.0e_Docs/HTML/MAN/MAN3/1795____.HTM

通过阅读文档,您可以看到此函数的返回值确定了原因:

ERRORS

  If the sigwait functions fail, errno is set to one of the following values:

  [EINVAL]   The value of the set parameter contains an invalid or
         unsupported signal number.

  [EINVAL]   The timeout argument specified a tv_nsec value that is less
         than 0 or greater than or equal to 1,000,000,000.

  [EINTR]    The wait was interrupted by an unblocked, caught signal.

  [EAGAIN]   No signal specified by set was delivered within the
         specified timeout period.

您可能需要检查该值是EAGAIN还是EINTR

这篇关于C等待时间或用SIGWAIT发信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆