Linux 在分段错误时未生成核心转储文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3948615/
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-08-04 23:41:02  来源:igfitidea点击:

Core dump file not generated on segmentation fault

clinuxgdbcoredump

提问by Tim

I am trying to debug a segmentation fault caused by my C program using gdb. A core dump file is not automatically generated when I run my program,and i have to run the command

我正在尝试使用gdb. 运行我的程序时不会自动生成核心转储文件,我必须运行命令

ulimit -c unlimited

for a core file to be generated on the next run.

以便在下次运行时生成核心文件。

Why is a core dump file not generated automatically and why do I have to run the ulimitcommand everytime to generate a core file on the next run of my program ?.

为什么没有自动生成核心转储文件,为什么我ulimit每次都必须运行该命令才能在下次运行程序时生成核心文件?。

The operating system i use is Ubuntu 10.10.

我使用的操作系统是 Ubuntu 10.10。

采纳答案by Michalis Giannakidis

You need to place the command

您需要放置命令

ulimit -c unlimited

in your environment settings.

在您的环境设置中。

If you are using bash as your shell, you need to place the above command in ~/.bashrc

如果你使用 bash 作为你的 shell,你需要将上面的命令放在 ~/.bashrc 中

回答by ninjalj

That's because by default your distribution limits core file size to 0 blocks. The ulimitcommand you mentioned increases that limit to infinity.

这是因为默认情况下,您的发行版将核心文件大小限制为 0 个块。ulimit您提到的命令将该限制增加到无穷大。

I don't know about Ubuntu, but most distros have a file /etc/limits with system defaults for resource limits.

我不了解 Ubuntu,但大多数发行版都有一个文件 /etc/limits,其中包含资源限制的系统默认值。

回答by user389238

You might also want to try to edit /etc/security/limits.conffile instead of adding ulimit -c unlimitedto ~/.bashrc.

您可能还想尝试编辑/etc/security/limits.conf文件而不是添加ulimit -c unlimited~/.bashrc.

The limits.confis the "correct" place where to specify core dump details in most Linux distros.

limits.conf是在大多数 Linux 发行版中指定核心转储详细信息的“正确”位置。

回答by user3910369

The segmentation fault is due to irrelevant values for path variables. On my system the user is sidd@sidd-Lenovo-G460and the contents added are as below.

分段错误是由于路径变量的值不相关。在我的系统上,用户是sidd@sidd-Lenovo-G460,添加的内容如下。

PATH=$PATH:/home/sidd/ns-allinone-2.35/bin:/home/sidd/ns-allinone-2.35/tcl8.5.10/unix:/home/sidd/ns-allinone-2.35/tk8.5.10/unix

LD_LIBRARY_PATH=/home/sidd/ns-allinone-2.35/otcl-1.14:/home/sidd/ns-allinone-2.35/lib

TCL_LIBRARY=/home/sidd/ns-allinone-2.35/tcl8.5.10/library

Please refer this blog post(VERY IMPORTANT).

请参考这篇博文(非常重要)。