I am testing code that is designed to detect when a child process has undergone undergoing. Imagine I'm surprised when this code is not always executed by sepfault:
#include <stdio.h> int main() { char *p = (char *)(unsigned long)0; putchar(*p); return 0; }
I am working under the Debian Linux 2.6.26 kernel; my shell is AT & T ksh93 from the Debian ksh package, version M 93s + 2008-01-31. Sometimes this program is segfault, but otherwise it just ends silently with a non-zero exit status, but without a message. My signal detection program reports the following:
segfault terminated by signal 11: Segmentation fault segfault terminated by signal 53: Real-time signal 19 segfault terminated by signal 11: Segmentation fault segfault terminated by signal 53: Real-time signal 19 segfault terminated by signal 53: Real-time signal 19 segfault terminated by signal 53: Real-time signal 19 segfault terminated by signal 53: Real-time signal 19
Running under pure ksh shows that segfault is also rare:
Running... Running... Running... Running... Running... Running... Memory fault Running...
Interestingly, bash correctly defines segfault every time .
I have two questions:
Can anyone explain this behavior?
Can anyone suggest a simple C program that will execute segfault reliably with every run? I also tried kill(getpid(), SIGSEGV) , but I get similar results.
EDIT: jbcreix has the answer : my segfault detector was broken. I was tricked because ksh has the same problem. I tried with bash , and bash always fixed this.
My mistake was that I passed WNOHANG to waitpid() , where I had to pass zero. I do not know what I could think of! I wonder what happened to ksh , but this is a separate issue.
c segmentation-fault linux waitpid
Norman ramsey
source share