Timeline for How does a Segmentation Fault work under-the-hood?
Current License: CC BY-SA 3.0
23 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 29, 2016 at 6:50 | comment | added | Loki Astari |
Try popen() rather than system()
|
|
| Jan 29, 2016 at 1:32 | comment | added | Braden Best | @BigHomie ah, it "doesn't work" in the sense that a thwarted bank robbery "doesn't work". Gotcha. | |
| Jan 29, 2016 at 1:30 | comment | added | MDMoore313 | It was a pun, ya know b/c the program that caused the seg fault is no longer working :'( | |
| Jan 29, 2016 at 1:29 | comment | added | Braden Best | @BigHomie what does "it" refer to? | |
| Jan 29, 2016 at 1:26 | comment | added | MDMoore313 | I have to say that by it's very nature, it doesn't work. | |
| Jan 27, 2016 at 23:02 | comment | added | Braden Best |
Mmkay, but why do that when I can have the kernel do it for me? char *p = 0; *p = 5; is a lot simpler to write than including a header like <sys/signal.h> and using library functions to trigger a signal.
|
|
| Jan 27, 2016 at 22:57 | comment | added | MatthewRock | @BradenBest you have option to call signal from your program, using standard C library. That's what I'm talking about. | |
| Jan 27, 2016 at 21:34 | comment | added | Braden Best |
@MatthewRock I know: kill -11 <pid>. But it's simpler to write a small program that segfaults than to: 1. write an infinite loop, 2. find the process with a tool like ps, 3. send SIGSEGV.
|
|
| Jan 27, 2016 at 17:00 | history | edited | Braiam |
edited tags
|
|
| Jan 27, 2016 at 13:14 | comment | added | MatthewRock |
Btw, you can emulate segfault by sending SIGSEGV.
|
|
| Jan 26, 2016 at 16:57 | comment | added | Gilles 'SO- stop being evil' | See also What happens after a page fault? | |
| Jan 26, 2016 at 16:25 | answer | added | Random832 | timeline score: 20 | |
| Jan 26, 2016 at 7:25 | comment | added | Braden Best |
@DietrichEpp Just as you said! I tried adding a check for (WIFSIGNALED(status) && WTERMSIG(status) == 11) to have it print something goofy ("YOU DUN GOOFED AND TRIGGERED A SEGFAULT"). When I ran the segfault program from within crsh, it printed exactly that. Meanwhile, commands that exit normally don't produce the error message.
|
|
| Jan 26, 2016 at 6:43 | comment | added | Dietrich Epp |
@BradenBest: Exactly. Read the manual page man 2 wait, it will include the macros WIFSIGNALED() and WTERMSIG().
|
|
| Jan 26, 2016 at 4:20 | vote | accept | Braden Best | ||
| Jan 26, 2016 at 4:04 | comment | added | Braden Best |
@DietrichEpp I had a feeling there was some kind of caveat like that with using system(). I hacked together a rewrite of crsh to use execvp (which was difficult, but taught me a lot about how forking works), and re-did the experiment. Had some interesting results: 1. The shell still did not crash. 2. It did not print "Segmentation Fault." I know this is rather inconclusive since I could have made a silly error, but from what I'm seeing, it looks like the shell is responsible for printing "Segmentation Fault". Thoughts?
|
|
| Jan 26, 2016 at 2:46 | comment | added | Dietrich Epp |
This is a nice experiment... but you should know what system() does under the hood. It turns out that system() will spawn a shell process! So your shell process spawns another shell process and that shell process (probably /bin/sh or something like that) is the one that runs the program. The way /bin/sh or bash works is by using fork() and exec() (or another function in the execve() family).
|
|
| Jan 26, 2016 at 2:44 | history | tweeted | twitter.com/StackUnix/status/691814003069292544 | ||
| Jan 26, 2016 at 2:03 | answer | added | zwol | timeline score: 267 | |
| Jan 26, 2016 at 1:41 | comment | added | jpmc26 |
When I first saw crsh, I thought it would be pronounced "crash." I'm not sure whether that's an equally fitting name.
|
|
| Jan 25, 2016 at 20:59 | answer | added | user732 | timeline score: 42 | |
| Jan 25, 2016 at 20:09 | answer | added | vonbrand | timeline score: 18 | |
| Jan 25, 2016 at 19:30 | history | asked | Braden Best | CC BY-SA 3.0 |