Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are segmentation faults reported?

I was just wondering how segmentation faults might get reported.

  • The process will just die, so obviously it cannot report it.
  • The shell would not know for sure unless the process passes a signal, which might not be the case necessarily.
  • The OS might be able to do something, but I am not sure how.

Which one of these reports the segmentation faults (just an example), and how?

like image 954
Lazer Avatar asked Feb 20 '23 07:02

Lazer


2 Answers

The process will just die, so obviously it cannot report it.

This is actually false. It is possible to install a SIGSEGV handler to replace the default one, which simply dumps core and dies. A preload library can do so to catch a segmentation violation and use the limited facilities available to notify another process running on the system of what has happened before exiting.

like image 167
Ignacio Vazquez-Abrams Avatar answered Feb 21 '23 19:02

Ignacio Vazquez-Abrams


If you take a look at the functions wait() or waitpid(), you will find that one of the bits in the exit status indicates a core dump. The POSIX specification mentions WIFSIGNALED [sic] and WTERMSIG to get the signal that terminated the process. The POSIX specification doesn't mention it, but on Mac OS X (10.7.4) for example, there's a WCOREDUMP() macro to test whether a core file was created.

like image 34
Jonathan Leffler Avatar answered Feb 21 '23 20:02

Jonathan Leffler