【发布时间】:2009-12-07 17:54:47
【问题描述】:
我不确定这是 C 库还是其他将内容转储到核心文件并使程序退出的东西。我的意思是 glibc 或 libc 处理 SIGSEGV 并在处理程序函数中创建核心转储?请解释一下。
【问题讨论】:
标签: coredump
我不确定这是 C 库还是其他将内容转储到核心文件并使程序退出的东西。我的意思是 glibc 或 libc 处理 SIGSEGV 并在处理程序函数中创建核心转储?请解释一下。
【问题讨论】:
标签: coredump
在linux中,内核进程执行和信号处理机制负责。
http://lxr.linux.no/#linux+v2.6.32/fs/exec.c#L1752
void do_coredump(long signr, int exit_code, struct pt_regs *regs)
{
...
http://lxr.linux.no/#linux+v2.6.32/kernel/signal.c#L1926
if (sig_kernel_coredump(signr)) {
if (print_fatal_signals)
print_fatal_signal(regs, info->si_signo);
/*
* If it was able to dump core, this kills all
* other threads in the group and synchronizes with
* their demise. If we lost the race with another
* thread getting here, it set group_exit_code
* first and our do_group_exit call below will use
* that value and ignore the one we pass it.
*/
do_coredump(info->si_signo, info->si_signo, regs);
【讨论】:
当没有其他处理程序时,如果进程的ulimit -c大于0,内核将生成核心文件。
【讨论】:
ulimit -c,你应该提到要传递的最有用的值是0 或unlimited。我没有遇到任何人假装她/他可以对截断的核心转储做任何事情。
内核是创建核心转储的东西,至少在 Linux 中是这样。
正如 Gonzalo 指出的那样,ulimit -c 确定核心转储的最大大小(0 完全禁用它,unlimited 指定无限制)。根据可用的磁盘空间,您可能希望将其设置为 unlimited 以外的某个值以防止填充磁盘,但您可能会发现很难使用截断的核心文件。
核心文件名可以使用/proc/sys/kernel/core_uses_pid和/proc/sys/kernel/core_pattern配置。
您可以使用kill -SEGV <pid> 来制作进程转储核心。
【讨论】:
我相信它是由内核处理的。不过,在 Linux 上,我还没有找到手动创建的库或系统调用。
【讨论】: