What are the scenarios where a process gets a SIGABRT in C++? Does this signal always come from within the process or can this signal be sent from one process to another?
Is there a way to identify which process is sending this signal?
What are the scenarios where a process gets a SIGABRT in C++? Does this signal always come from within the process or can this signal be sent from one process to another?
Is there a way to identify which process is sending this signal?
You can send any signal to any process using the
kill(2)
interface:kill -SIGABRT 30823
30823 was a
dash
process I started, so I could easily find the process I wanted to kill.The
Aborted
output is apparently howdash
reports a SIGABRT.It can be sent directly to any process using
kill(2)
, or a process can send the signal to itself viaassert(3)
,abort(3)
, orraise(3)
.In my case, it was due to an input in an array at an index equal to the length of the array.
x[5] is being accessed which is not present.
There's another simple cause in case of c++.
i.e. scope of thread ended but you forgot to call either
or
SIGABRT
is commonly used by libc and other libraries to abort the program in case of critical errors. For example, glibc sends anSIGABRT
in case of a detected double-free or other heap corruptions.Also, most
assert
implementations make use ofSIGABRT
in case of a failed assert.Furthermore,
SIGABRT
can be sent from any other process like any other signal. Of course, the sending process needs to run as same user or root.It usually happens when there is a problem with memory allocation.
It happened to me when my program was trying to allocate an array with negative size.
The GNU libc will print out information to
/dev/tty
regarding some fatal conditions before it callsabort()
(which then triggersSIGABRT
), but if you are running your program as a service or otherwise not in a real terminal window, these message can get lost, because there is no tty to display the messages.See my post on redirecting libc to write to stderr instead of /dev/tty:
Catching libc error messages, redirecting from /dev/tty