I have added a sighandler for SIGABRT
signal.
The default behavior of abort()
is to generate a core-dump.
I would like to do the same in signal handler but before crashing, execute cleanup code.
I have tried as below and I know that below piece of code is not going to work.
static void
proc_sigabort_handler (int signo UNUSED)
{
/* cleanup */
abort(); /* This is to coredump */
}
signal(SIGABRT, proc_sigabort_handler);
Problem:
abort()
call in sighandler raises SIGABRT
signal and end up in same sighandler function and this goes on.
Is there any syscall similar to abort()
to generate a core-dump?
Edit after some replies:
user@srv1 ~/linux> uname -a
Linux srv1 2.4.21-63.ELsmp #1 SMP Wed Oct 28 23:15:46 EDT 2009 i686 i686 i386 GNU/Linux
Linux abort(3) man Page:
If the SIGABRT signal is ignored, or caught by a handler that returns, the abort() function will still terminate the process. It does this by restoring the default disposition for SIGABRT and then raising the signal for a second time.
Ex:
void mysigabort()
{
printf("I caught the SIGABRT signal!\n");/* I know that printf should be avoided */
return;
}
int main()
{
signal(SIGABRT, mysigabort);
while(1); /* infinite loop */
exit(0);
}
Produces:
user@srv1 ~/linux> ./a.out
I caught the SIGABRT signal!
<cursor>
user@srv1 ~/linux> kill -6 25208
No cores found. Even process is not terminated.
If there is no user-defined signal handler, core is generated.