- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
下面的代码来自 Unix 环境中的高级编程,W. Richard Stevens
关于这本密码书说;
"If the signal is sent to the process while it is blocked, the signal delivery will be deferred until the signal is unblocked. To the application, this can look as if the signal occurs between the unblocking and the pause (depending on how the kernel implements signals). If this happens, or if the signal does occur between the unblocking and the pause, we have a problem. Any occurrence of the signal in this window of time is lost in the sense that we might not see the signal again, in which case the pause will block indefinitely. This is another problem with the earlier unreliable signals."
它建议在重置信号掩码之前使用 sigsuspend()
而不是 pause()
因为它会重置信号掩码并使进程在单个原子中休眠手术。但我不希望我的进程等到信号在走出临界区后才出现。 那么这个问题也适用于我的情况吗?如果是这样,在使用 sigprocmask()
重置信号掩码时我应该使用什么来不丢失信号?
sigset_t newmask, oldmask;
sigemptyset(&newmask);
sigaddset(&newmask, SIGINT);
/* block SIGINT and save current signal mask */
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
err_sys("SIG_BLOCK error");
/* critical region of code */
/* reset signal mask, which unblocks SIGINT */
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
err_sys("SIG_SETMASK error");
/* window is open */
pause(); /* wait for signal to occur */
/* continue processing */
最佳答案
使用 sigsuspend 是为了避免 sigprocmask 和 pause 之间的过程。如果在收到信号之前不需要暂停线程,那么 sigsuspend 无法为您做任何事情。您没有提供足够的信息来了解您的上下文中是否还有其他问题来源。
关于c - sigprocmask() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5688607/
我正在阅读有关 Linux x86-64 系统的信号/ECF 的教科书章节(CS:APP,第 3 版,第 8 章,第 781 页),并遇到了这个: The sigsuspend function te
我有使用 sigprocmask fn 的多线程代码。据我了解,在多线程程序中未指定此调用的使用,我将删除此调用。但是,我面临的问题是,如果调用此函数,我的主线程将被卡住。我想了解为什么会发生这种情况
我的 C Unix 代码有问题。我将复制关键部分:因此,在第一个 sigprocmask 之后,我发送了一个信号,在 SIG_UNBLOCK 之后,前一个句柄(gestisciSignalDopoRe
下面的代码来自 Unix 环境中的高级编程,W. Richard Stevens 关于这本密码书说; "If the signal is sent to the process while it is
我目前正在研究使用 sigprocmask 在关键代码段时阻止某些信号(在本例中为 SIGALRM 和 SIGCHLD)正在执行。与这些信号关联的两个信号处理程序都将访问和修改一个中央数据结构,因此在
在多线程应用程序中使用 sigprocmask() 时,是否有任何众所周知的原因导致段错误? 我有一个使用 clone() 创建多个线程的应用程序。我已经确定,出于某种原因,当我使用 sigprocm
我想在汇编中使用 sigprocmask 来阻止函数中的所有信号。 以下代码在 C 中有效: #include #include int main() { sigset_t n={(uns
我有一个奇怪的行为,联机帮助页和谷歌没有帮助。 在我的代码中,我想在发送 SIGUSR2 时阻止/取消阻止 SIGINT。为此,我安装了信号处理程序并在函数中准备了掩码集: void installS
来自man sigprocmask: "If oset is not null, it is set to the previous value of the signal mask." 我的问题:无
我写了一小段代码。此代码首先阻止 {SIGSEGV},然后将 SIGRTMIN 添加到同一组。所以,我的最终信号集是 {SIGSEGV,SIGRTMIN}。因此,如果我使用 SIG_UNBLOCK,根
在第 10 章 APUE 信号中。 我对 sigprocmask()、SIG_BLOCK 和 SIG_SETMASK 有一些疑问。 书上说“我们在屏蔽信号时保存了旧面具”。我的理解是: 我们声明一个s
我还没有完全理解,如何使用sigprocmask()。特别是 set 和 oldset 及其语法如何工作以及如何使用它们。 int sigprocmask(int how, const sigset_
修订摘要 好吧,看起来系统调用肯定与 GC 有关,而根本问题只是 GC 发生得太频繁了。这似乎与 splitWhen 和 pack 的使用有关,我可以通过分析来判断。 splitWhen's impl
结构 sigaction: struct sigaction { void (*sa_handler)(int); /* addr of signal handler, *
我是一名优秀的程序员,十分优秀!