Reputation: 23
I am getting core dump while running below program:
$ cat test2.c
#include <stdio.h>
#include <stdlib.h>
void main()
{
abort();
}
$
$ cc -o test2 test2.c
"test2.c", line 5: warning #2951-D: return type of function "main" must be
"int"
void main()
^
$ ./test2
Abort(coredump)
$
I have received a SIGABRT signal. Kindly suggest me the ways to handle this SIGABRT signal.
Upvotes: 0
Views: 4276
Reputation: 725
// here's same code w/signal handler
$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void abort_handler(int);
void main()
{
if (signal(SIGABRT, abort_handler) == SIG_ERR) {
fprintf(stderr, "Couldn't set signal handler\n");
exit(1);
}
abort();
exit(0);
}
void abort_handler(int i)
{
fprintf(stderr, "Caught SIGABRT, exiting application\n");
exit(1);
}
$ cc -o test test.c
$ ./test
Caught SIGABRT, exiting application
$
Upvotes: 2
Reputation: 229204
You normally should not handle it, the purpose of calling abort() is to produce a core dump and terminate your program, just as your program does.
Upvotes: 3
Reputation: 4869
remove abort()
from your main...
if you want to leave main: return;
if you want to leave the program in any place: exit()
if you really want to handle the signal, install a signal handler see: http://www.manpagez.com/man/2/sigaction/
hth
Mario
Upvotes: 3