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.
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.
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.
When there's no other handler, the kernel will generate the core file if ulimit -c
is greater than 0 for the process.
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);