2006-01-01 18:26:52 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int doit = 0;
|
|
|
|
void
|
|
|
|
ouch (int sig)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "ouch %d\n", sig);
|
2006-01-01 19:02:54 +01:00
|
|
|
if (doit++ > 0)
|
2006-01-01 18:26:52 +01:00
|
|
|
kill (getpid (), SIGTERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
static struct sigaction act;
|
|
|
|
if (argc == 1)
|
|
|
|
act.sa_flags = SA_RESETHAND;
|
|
|
|
act.sa_handler = ouch;
|
2006-01-01 19:02:54 +01:00
|
|
|
sigaction (SIGSEGV, &act, NULL);
|
2006-01-01 18:26:52 +01:00
|
|
|
int pid = fork ();
|
|
|
|
int status;
|
|
|
|
if (pid > 0)
|
|
|
|
waitpid (pid, &status, 0);
|
|
|
|
else
|
|
|
|
{
|
2006-01-01 19:02:54 +01:00
|
|
|
int *i = 0;
|
|
|
|
*i = 9;
|
|
|
|
exit (0x42);
|
2006-01-01 18:26:52 +01:00
|
|
|
}
|
2006-01-02 05:01:22 +01:00
|
|
|
status &= ~0x80; // remove core dump flag
|
2006-01-02 04:45:32 +01:00
|
|
|
fprintf (stderr, "pid %d exited with status %p\n", pid, (void *) status);
|
2006-01-01 19:02:54 +01:00
|
|
|
exit (argc == 1 ? !(status == SIGSEGV) : !(status == SIGTERM));
|
2006-01-01 18:26:52 +01:00
|
|
|
}
|