为什么会生成核心转储文件?

发布于 2024-07-17 20:09:38 字数 364 浏览 3 评论 0原文

有时,当我运行代码时,通过 Ctrl+\ 终止程序时会生成核心转储文件。 文件名的格式为core.*。 程序不会突然终止,并且不存在分段错误。 我相信它是 SIGQUIT 而不是 SIGABRTSIGSEGV。 如果我尝试 Ctrl+CCtrl+Z,则不会生成它。

谁能告诉我为什么只有在按下 Ctrl+\ 时才会生成它? 如何避免生成此核心转储文件? 核心转储文件有什么用吗?

Sometimes when I run my code, a core dump file is generated when I terminate the program by Ctrl+\. The file name is of the form core.*. The program is not terminating abruptly, and there is no segmentation fault. I believe it is SIGQUIT and not SIGABRT or SIGSEGV. If I try Ctrl+C, or Ctrl+Z, then it is not generated.

Can anyone tell why it is generated only when Ctrl+\ is pressed? How can I avoid this core dump file from being generated? Is there any use for the core dumped file?

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

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

发布评论

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

评论(7

寄离 2024-07-24 20:09:38

当进程因程序错误而被操作系统终止时,进程会转储核心。 发生这种情况的最典型原因是程序访问了无效的指针值。 鉴于您有零星的转储,您可能正在使用未初始化的指针。

您能发布导致错误的代码吗? 除了模糊的概括之外,在不实际查看代码的情况下很难猜测出了什么问题。

至于核心转储实际上是什么,请查看这篇维基百科文章:

A process dumps core when it is terminated by the operating system due to a fault in the program. The most typical reason this occurs is because the program accessed an invalid pointer value. Given that you have a sporadic dump, it's likely that you are using an uninitialized pointer.

Can you post the code that is causing the fault? Other than vague generalizations it's hard to guess what's wrong without actually seeing code.

As for what a core dump actually is, check out this Wikipedia article:

千笙结 2024-07-24 20:09:38

正如其他人之前所说,核心转储是程序错误的结果。

您可以使用 ulimit 命令配置是否生成核心转储。 输入

ulimit -c 0

将禁用活动 shell 中的核心文件生成。

如果生成核心的程序是使用符号信息构建的,您可以进行事后调试会话像这样:

gdb <pathto/executable> --core <corefilename>

As said by others before the core dump is the result of a fault in the program.

You can configure if a core dump is to be generated with the ulimit command. Entering

ulimit -c 0

disables core file generation in the active shell.

If the program that generated the core was built with symbol information you can do a post mortem debugging session like this:

gdb <pathto/executable> --core <corefilename>
困倦 2024-07-24 20:09:38

ctrl + \ 向进程发送信号 SIGQUIT。 根据POSIX.1标准,该信号的默认操作是生成一个核心。

SIGILL、SIGABRT、SIGFPE、SIGSEGV 是系统生成核心的其他情况。

请参阅您系统上的“man 7 signal”了解更多详细信息。

ctrl + \ sends signal SIGQUIT to the process. According to POSIX.1 standard, the default action for this signal is to generate a core.

SIGILL, SIGABRT, SIGFPE, SIGSEGV are other cases when system will generate a core.

Please refer "man 7 signal" on your system for more details.

简单气质女生网名 2024-07-24 20:09:38

当进程接收到某些信号(例如 SIGSEGV)时,就会生成核心转储,该信号是内核在访问其地址空间之外的内存时发送的。 通常,发生这种情况是由于指针使用方式错误造成的。 这意味着程序中存在错误。

核心转储对于查找错误很有用。 它是出现问题时进程内存的映像,因此可以使用 gdb 等调试器来查看程序当时正在做什么。 调试器甚至可以(有时)访问程序中变量的值。

您可以使用 ulimit 命令防止发生核心转储。

Core dumps are generated when the process receives certain signals, such as SIGSEGV, which the kernels sends it when it accesses memory outside its address space. Typically that happens because of errors in how pointers are used. That means there's a bug in the program.

The core dump is useful for finding the bug. It is an image of the the process's memory at the time of the problem, so a debugger such as gdb can be used to see what the program was doing then. The debugger can even access (sometimes) the values of variables in the program.

You can prevent core dumps from happening using the ulimit command.

平定天下 2024-07-24 20:09:38

它是一个帮助调试表现不佳的应用程序的工具。 它很大,因为它包含应用程序死亡时所有应用程序物理内存的内容以及所有线程的寄存器状态和堆栈。

当内核因执行某些邪恶操作(例如生成分段冲突或总线错误)而终止应用程序时,就会生成它们。

It's a tool to aid in debugging an application that's behaving badly. It's large because it contains the contents of all the applications physical memory at the time it died as well as the register states and stacks of all its threads.

They get generated when the kernel kills an application for doing something evil, like generating a segmentation violation or a bus error.

梦回旧景 2024-07-24 20:09:38

您可以通过编写不会崩溃的代码来避免创建核心转储文件:)

说真的,核心转储很有用,因为您可以在程序崩溃时查看程序的状态,以进行“事后”调试。 您可以在 gdb 中打开它们并检查程序的状态(特别是如果它是通过调试构建的)。

如果程序有 SIGSEGV(通常由无效的指针取消引用引起)、SIGABRT(如果您调用 abort() 或在 C++ 中通过默认的终止()处理析构函数等中的异常,则会发生这种情况)或某些情况,通常会生成核心转储其他故障。 您还可以使用调试器或以编程方式显式触发它们。

如果您已经修复了所有错误并且完美,则可以将其删除。 另外,如果您以任何方式更改了程序(并重新编译了它),那么它们将变得毫无用处,因为调试信息现在与核心转储中的内容不匹配,因此您也可以删除它们。

You can avoid creating a core dump file by writing code that doesn't crash :)

Seriously, core dumps are useful because you can see the state of the program when it crashed, for "post mortem" debugging. You can open them in gdb and inspect the state of your program (especially if it was built with debugging).

Core dumps usually get made if the program has a SIGSEGV (usually caused by invalid pointer dereferencing), SIGABRT (which would happen if you called abort(), or in C++ by the default terminate() handler for exceptions in destructors etc) or some other fault. You can also trigger them explicitly with the debugger or programmatically.

If you've fixed all the bugs and it's perfect, you can delete them. Also, if you've changed your program in any way (and recompiled it) then they will become useless as the debug info now won't match what's in the core dump, so you can delete them then too.

森罗 2024-07-24 20:09:38

Ctrl + \ 的作用是生成核心转储。 这就是 SIGQUIT 的作用。 如果您不希望生成它,请使用 Ctrl + C (SIGINT)。 如果相关程序没有响应 SIGINT 但您需要从终端终止它,则您或开发人员做错了什么。

设计为从终端使用 Ctrl + C 终止的程序仍应优雅地响应 SIGTERM,这可以通过 kill -TERM ... 在另一个终端中触发。 如果所有其他方法都失败,SIGKILL 将强制立即终止。

The point of Ctrl + \ is to generate a core dump. That's what SIGQUIT does. If you don't want it to be generated, use Ctrl + C (SIGINT) instead. If the program in question is not responding to SIGINT but you need to kill it from the terminal, either you or the developer is doing something wrong.

Programs designed not to be killed from the terminal with Ctrl + C should still respond gracefully to SIGTERM, which can be triggered in another terminal via kill -TERM .... If all else fails, SIGKILL will force an immediate termination.

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