Do you have to do it from within the program itself, or can you use a wrapper program? You generally can't recover from a SIGSEGV, but a wrapper program can easily see that a child process died from a signal and which one (from $?, and can also easily capture its output by setting up pipes as the child process's STDIN and STDOUT.