C语言 如何在 Ubuntu 中生成核心转储文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6152232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 08:46:59  来源:igfitidea点击:

How to generate core dump file in Ubuntu

ccoredump

提问by user496934

I would like to know how to generate a core dump file in Ubuntu. I am using Ubuntu 8.04.1 and gcc compiler 4.2.3. I have written a simple C program to generate a core dump. I have compiled the program as in -- gcc -g badpointer.c . When I run the program its gives segmentation fault but no core dump is generated. What additional things do i have to do to generate a core dump file ?

我想知道如何在 Ubuntu 中生成核心转储文件。我使用的是 Ubuntu 8.04.1 和 gcc 编译器 4.2.3。我编写了一个简单的 C 程序来生成核心转储。我已经按照 --gcc -g badpointer.c 中的方式编译了程序。当我运行程序时,它给出了分段错误,但没有生成核心转储。我还需要做什么来生成核心转储文件?

回答by kenorb

Linux

Linux

Activate your coredumps by the following command:

通过以下命令激活您的核心转储:

ulimit -c unlimited

Also, check the core_patternvalue by:

另外,core_pattern通过以下方式检查值:

sysctl kernel.core_pattern

to see where your dumps are created (%ewill be the process name, and %twill be the system time).

查看创建转储的位置(%e将是进程名称,%t将是系统时间)。

You can change it in /etc/sysctl.conf and then reload by sysctl -p.

您可以在 /etc/sysctl.conf 中更改它,然后通过sysctl -p.

You can test it by:

您可以通过以下方式进行测试:

sleep 10 &
killall -SIGSEGV sleep

If core dumping is successful, you will see “(core dumped)” after the segmentation fault indication. Otherwise double-check your ulimits again.

如果核心转储成功,您将在分段错误指示后看到“(core dumped)”。否则,请ulimit再次仔细检查您的s。

See also:

也可以看看:



Ubuntu

Ubuntu

If you've Ubuntu, your dumps are created by Apportin /var/crash, however it's disabled by default.

如果你有 Ubuntu,你的转储是由Apport在中创建的/var/crash,但默认情况下它是禁用的。

For more details, check: Where do I find the core dump in Ubuntu?

有关更多详细信息,请检查:我在哪里可以找到 Ubuntu 中的核心转储?



macOS/OS X

macOS/OS X

In macOS, crash dumps are automatically created by Crash Reporterin form of backtraces. You can find these crash files by executing Consoleand going to 'User Diagnostic Reports' section (under 'Diagnostic and Usage Information' group) or you can locate them in ~/Library/Logs/DiagnosticReports.

在 macOS 中,崩溃转储由Crash Reporter以回溯的形式自动创建。您可以通过执行Console并转到“用户诊断报告”部分(在“诊断和使用信息”组下)来找到这些崩溃文件,也可以在~/Library/Logs/DiagnosticReports.

The actual core files are generated in /cores.

实际的核心文件在/cores.

Read more: How to generate core dumps in Mac OS X?

阅读更多:如何在 Mac OS X 中生成核心转储?

回答by Cédric Julien

Check the ouput of ulimit -c, if it output 0, this is why you don't have core dumped.

检查 的输出ulimit -c,如果它输出 0,这就是你没有核心转储的原因。

Use

ulimit -c unlimited

ulimit -c unlimited

to allow core creation (maybe replace unlimitedby a real size limit to be more secure) .

允许创建核心(可能替换unlimited为真实大小限制以更安全)。

回答by lhf

Set a max core dump size with ulimit -cSIZE.

使用ulimit -cSIZE设置最大核心转储大小。