为什么“暂停”?系统调用总是返回-1?

发布于 2024-12-17 22:36:22 字数 121 浏览 0 评论 0原文

或者,为什么我们不能简单地将暂停声明为:

#include <unistd.h>
void pause(void);

因为暂停的返回值是没有意义的。

or, why can't we simply declare pause as:

#include <unistd.h>
void pause(void);

since the return value of pause is meaningless.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め可乐爱微笑 2024-12-24 22:36:23

来自pause

RETURN VALUE

   pause()  only  returns when a signal was caught and the signal-catching
   function returned.  In this case pause() returns -1, and errno  is  set
   to EINTR.

每个被中断的系统调用都会得到EINTR(或者在特殊情况下得到ERESTART)。我认为没有理由让 pause 成为例外!

当然,您可以在代码中编写 (void)pause (); 来忽略结果。

From man page of pause

RETURN VALUE

   pause()  only  returns when a signal was caught and the signal-catching
   function returned.  In this case pause() returns -1, and errno  is  set
   to EINTR.

Every syscall which is interrupted is getting EINTR (or ERESTART in peculiar cases). I see no reason to make pause an exception!

Of course you are free to write (void) pause (); in your code to ignore the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文