6

(Here I'm targeting only Linux)

I'm assuming core is generated by the glibc's default signal handler.

But if I google most of result says OS generate a core dump. If OS generates core, signal handler will be called first (or) core dumped first?

Arunprasad Rajkumar
  • 1,374
  • 1
  • 15
  • 31

1 Answers1

9

The kernel itself generates the coredump. See the core handling routines in the linux kernel source here:

http://lxr.linux.no/linux+v3.12.6/fs/coredump.c

If the process receives any of the following signals 1, the kernel responds by attempting a coredump.

#define SIG_KERNEL_COREDUMP_MASK (\
rt_sigmask(SIGQUIT)   |  rt_sigmask(SIGILL)    | \
rt_sigmask(SIGTRAP)   |  rt_sigmask(SIGABRT)   | \
rt_sigmask(SIGFPE)    |  rt_sigmask(SIGSEGV)   | \
rt_sigmask(SIGBUS)    |  rt_sigmask(SIGSYS)    | \
rt_sigmask(SIGXCPU)   |  rt_sigmask(SIGXFSZ)   | \
SIGEMT_MASK  

This coredump is configurable, and can be disabled or controlled in several ways, including the file /proc/sys/kernel/core_pattern, and ulimit. One can also control the delivery of these signals through the signal handling mechanisms.

Peter
  • 14,559
  • 35
  • 55
  • core dumped first or signal handler called first? – Arunprasad Rajkumar Jan 08 '14 at 05:14
  • 3
    Sequence is: 1- event occurs (like segmentation fault) 2- kernel notifies process of this event by signal 3- process handles signal (either user-installed or default handler) 4- In most cases, the above signals trigger the coredump action via the default signal handler. – Peter Jan 08 '14 at 14:19