tags:

views:

221

answers:

4

I am unsure whether this is the C library or some other stuff which dumps contents to core file and make a program Exit. What i mean here is that is the glibc or libc handles the SIGSEGV and creates the core dump in the handler function ? Please explain.

+3  A: 

The kernel is what creates the core dump, at least in Linux.

As Gonzalo points out, ulimit -c determines the maximum size of the core dump (with 0 disabling it completely and unlimited specifying no limit). Depending on available disk space, you may want to set this to some value other than unlimited to prevent filling a disk, though you'll likely find it hard to use the truncated core file.

The name of the core file can be configured using /proc/sys/kernel/core_uses_pid and /proc/sys/kernel/core_pattern.

You can use kill -SEGV <pid> to make a process dump core.

retracile
Thanks a lot for the information
Amit
+1  A: 

I believe that it is handled by the kernel. On Linux, I have not found a library or system call to create one manually, though.

Michael E
You can send a SEGV signal with `kill`...
retracile
And if you're inside gdb, you can execute 'generate-core-file'
Gonzalo
+4  A: 

When there's no other handler, the kernel will generate the core file if ulimit -c is greater than 0 for the process.

Gonzalo
If you mention `ulimit -c`, you should mention that the most useful values to pass are either `0` or `unlimited`. I have not met anyone who pretended s/he could do anything with a truncated core dump.
Pascal Cuoq
Heh. I've only set it to something other than those values looong time ago when disk quota was a constraint. Anyway, I just tried to use a truncated core file in gdb and got a decent error message: "Warning: /tmp/core is truncated: expected core file size >= 147456, found: 12288."
Gonzalo
A: 

In linux, the kernel process execution and signal handling mechanisms are responsible.

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);
Joe Koberg