- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
这个问题是针对 Linux 提出的。使用 GCC 编译器。
如果 SIGSEGV(我的意思是通常会导致 SIGSEGV 的违规行为)发生在旨在捕获 SIGSEGV 的信号处理程序中,可以预期会有什么行为?有助于讨论的代码示例:
/* In main or whatever */
{
struct sigaction sa = {}; /* initialised to all zero (I vote for GCC style breach of standard here) */
sa.sa_handler = DisasterSignals;
sa.sa_flags = SA_RESETHAND | SA_NODEFER; /* To have or have not */
sigaction(SIGSEGV, &sa, NULL);
}
static void DisasterSignals(int signal)
{
/* We cannot save the situation, the purpose of catching the signal is
only to do something clever to aid debugging before we go. */
/* Q: What if we segfault in here?? */
abort(); /* This should give us the expected core dump (if we survive to this point) */
}
想象一下,在点“Q”中,有一个违规的机器指令。
1) 没有 SA_RESETHAND | SA_NODEFER
:这似乎将系统置于逻辑陷阱中:在“Q”处,应该生成 SIGSEGV。但是 SIGSEGV 在信号处理程序中被阻止(默认 sigaction 行为)。死刑如何继续?会结冰吗?它会跳过有问题的指令吗(我猜不会)?
2) 使用 SA_RESETHAND | SA_NODEFER
:我猜在这种情况下,当重复 SIGSEGV 时,程序将以“正常”方式崩溃。
3) 只有 SA_NODEFER
:我猜在这种情况下,信号处理程序在重复 SIGSEGV 时被递归调用;如果 SIGSEGV 总是重复,我们会卡住直到堆栈溢出,然后呢。
最佳答案
默认情况下,在处理信号时它会被屏蔽,因此无法递归触发。如果屏蔽信号由程序执行触发(无效内存访问、段错误、除以 0 等),则行为未定义:
If SIGBUS, SIGFPE, SIGILL, or SIGSEGV are generated while they are blocked, the result is undefined, unless the signal was generated by kill(2), sigqueue(3), or raise(3).
在我的系统上,它会导致进程崩溃。
SA_NODEFER
没有屏蔽,因此可以递归处理信号,直到堆栈溢出。添加 SA_RESETHAND
将恢复默认操作(SIGSEGV 崩溃)。
我将您的示例改编为简单的测试程序,因此您可以验证此行为:
#include<signal.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
volatile char *ptr;
static void DisasterSignals(int signal)
{
/* We cannot save the situation, the purpose of catching the signal is
only to do something clever to aid debugging before we go. */
write(1, "11\n", 3);
*ptr = 1;
write(1, "13\n", 3);
abort(); /* This should give us the expected core dump (if we survive to this point) */
}
struct sigaction sa = {}; /* initialised to all zero (I vote for GCC style breach of standard here) */
int main()
{
sa.sa_handler = DisasterSignals;
sa.sa_flags = /*SA_RESETHAND | */SA_NODEFER; /* To have or have not */
sigaction(SIGSEGV, &sa, NULL);
write(1, "25\n", 3);
*ptr = 1;
}
关于c - 如果我捕捉到 SIGSEGV 并且信号处理程序导致另一个 SIGSEGV,会发生什么情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33265851/
这个问题是针对 Linux 提出的。使用 GCC 编译器。 如果 SIGSEGV(我的意思是通常会导致 SIGSEGV 的违规行为)发生在旨在捕获 SIGSEGV 的信号处理程序中,可以预期会有什么行
我正在构建一个 C++ 程序,我需要在其中处理 SIGSEGV 并且信号处理程序应该能够打印回溯。任何人都可以帮忙吗。 问候 最佳答案 获得 SIGSEV 回溯的最好方法是生成核心文件而不是打印回溯。
我有一个屏幕A,在执行了一些POST API任务后,我启用了一个按钮,然后单击按钮导航到屏幕B。当Reaction Native应用程序冻结并崩溃时,崩溃会随机发生。从其他屏幕导航到屏幕B也不是问题,
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我正在编写这个方法(C 语言),它应该为链表创建一个新节点。它在第一个 if (SIGSEGV 信号)之后的行崩溃 我正在调试该方法,因此后续行中可能会有更多错误,但目前我将感谢有关此特定行的任何观察
这是我的比较函数: int compareInts(const void *a, const void *b) { const int *pa = (const int*)a; con
我一直在研究一些有缺陷的代码,并想安装一个 SIGSEGV 处理程序来获取有关崩溃的更多信息。但是,我注意到我的处理程序没有被调用。 我一直在寻找原因,它似乎与损坏的堆栈指针值有关(它肯定没有被屏蔽)
我是编码新手。当我在 codecheff 中提交代码时,它给出“运行时错误(SIGSEGV)”。我不知道有什么问题请帮忙。提前致谢。 int call(int *x, int m) { int
CodeChef 问题: Shivam 是世界上最年轻的程序员,他只有 12 岁。 Shivam 正在学习编程,今天他正在编写他的第一个程序。 程序很简单,给定两个整数A和B,编写一个程序将这两个数字
我正在编写一个编程问题的解决方案。问题如下: Your program is to use the brute-force approach in order to find the Answer t
好吧,只是为了好玩,我正在研究埃拉托色尼筛。它最初运行良好,因此我寻求提高其运行时复杂性。现在,我不知道为什么,但我遇到了段错误。代码如下: #include #include int main(
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在创建一个简单的链表程序来插入和查看 LL 的元素。当我尝试插入第二个元素时,它给出 SIGSEV,但我不明白为什么?!! 请帮我指出问题: main.c: #include #includ
我试图提交此代码以解决 hackerearth 上的问题,但我得到了此 SIGSEGV 运行时错误。我读到了这个错误,但我无法让我的代码工作。有人说这是由于无效的内存引用、数组的动态初始化或数组索引超
我正在思考 leetcode 问题 167,但我的代码遇到了段错误 (SIGSEGV) 问题。下面是我的c代码,预期的答案是[1,3]。 #include #include /** * Return
我有一个在ARM平台上运行的多线程程序。在其中一个线程中,我将调用 system() 来运行某些 shell 命令。最近,我发现有时候,由system() fork 的子进程会以SIGSEGV终止。
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我很高兴知道为什么我遇到此错误 http://www.codechef.com/problems/AXR1P2在 codechef.com 中,我的代码是... #include #include i
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我正在使用 POSIX 套接字在 Android 上编写一些网络代码,但是当我调用 Sento 时,我收到了一个奇怪的 SIGSEGV(信号 11,代码 1)。我已经使用墓碑跟踪来确定它是哪一行,但坦
我是一名优秀的程序员,十分优秀!