核心转储被截断。

25

我正在设置

ulimit -c unlimited. 

在 C++ 程序中,我们正在进行:

struct rlimit corelimit;
  if (getrlimit(RLIMIT_CORE, &corelimit) != 0) {
    return -1;
  }
  corelimit.rlim_cur = RLIM_INFINITY;
  corelimit.rlim_max = RLIM_INFINITY;
  if (setrlimit(RLIMIT_CORE, &corelimit) != 0) {
    return -1;
  }

但是无论何时程序崩溃,由它生成的核心转储都会被截断。

BFD: Warning: /mnt/coredump/core.6685.1325912972 is truncated: expected core file size >= 1136525312, found: 638976.

可能会出现什么问题?

我们正在使用 Ubuntu 10.04.3 LTS

Linux ip-<ip> 2.6.32-318-ec2 #38-Ubuntu SMP Thu Sep 1 18:09:30 UTC 2011 x86_64 GNU/Linux

这是我的/etc/security/limits.conf文件

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - an user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#        - NOTE: group and wildcard limits are not applied to root.
#          To apply a limit to the root user, <domain> must be
#          the literal username root.
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#        - chroot - change root to directory (Debian-specific)
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#    ftp             -       chroot          /ftp
#@student        -       maxlogins       4



#for all users
* hard nofile 16384
* soft nofile 9000

更多细节

我正在使用gcc优化标志

O3 

我正在将堆栈线程大小设置为0.5 mb


4
你确认在/mnt/coredump所在的分区里有足够的空间吗? - ugoren
生成的核心文件大小是多少? - SoapBox
1
内核漏洞?请参见https://bugzilla.redhat.com/show_bug.cgi?id=575483(在新版本中已修复,但可能仍存在于您的Ubuntu版本中?) - Jayan
请执行命令"ulimit -c",以确定您的进程在哪里崩溃时的输出。 - Jörg Beyer
ulimit -c 给出 0。我认为是无限制的。 - Vivek Goel
显示剩余5条评论
6个回答

6

如果您正在使用 coredumpctl,可能的解决方案是编辑 /etc/systemd/coredump.conf 文件并增加 ProcessSizeMaxExternalSizeMax 的值:

[Coredump]
#Storage=external
#Compress=yes
ProcessSizeMax=20G
ExternalSizeMax=20G
#JournalSizeMax=767M
#MaxUse=
#KeepFree=

在此之后,可能还应该执行以下操作:sudo systemctl daemon-reload && sudo systemctl restart systemd-coredump.socket - Roman Orekhov

3

我曾经遇到过核心文件被截断的问题。

进一步调查显示,ulimit -f(也称为文件大小RLIMIT_FSIZE)也会影响核心文件,因此请检查该限制是否无限制/适当高。[我在Linux内核3.2.0 / Debian wheezy上看到了这个问题。]


3

我记得管理员可以设置一个硬性限制和用户设置的软性限制。如果软性限制比硬性限制更强,则取硬性限制值。

不过,我不确定这对所有shell都有效,我只知道它适用于bash。


5
或许你应该详细说明如何检查硬限制? - André Puel

1

硬限制和软限制有一些具体细节,可能会有点棘手:请参阅this,了解使用sysctl使名称更改持久的方法。

有一个文件可以编辑,应该可以使限制大小持久,尽管可能有相应的sysctl命令可以实现这一点...


0

当我使用kill -3手动杀死程序时,出现了类似的问题。这是因为我没有等待足够的时间来生成核心文件。

确保文件停止增长,并且只有在此之后再打开它。


0

当使用自动化错误报告工具 (abrt) 时,此解决方案有效。

在尝试了所有已建议的方法(无效)后,我在 /etc/abrt/abrt.conf 中找到了另一个影响转储文件大小的设置。

MaxCrashReportsSize = 5000

并增加了它的价值。

然后重新启动 abrt 守护进程:sudo service abrtd restart,重新运行崩溃的应用程序,并获得完整的核心转储文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接