How can I rerun a program with gdb until a segmentation fault occurs?

Solution 1:

Put a breakpoint at the exit of your program that triggers the run command, and don't forget set pagination off. Information on settings commands is available in the Breakpoint Command Lists section of the gdb documentation. In short:

set pagination off
break _exit
commands
run
end

After the commands line you'll see that the next two lines are being entered as the command to execute when the breakpoint is reached.

Solution 2:

(gdb) set pagination off
(gdb) break exit
(gdb) commands
>run
>end
(gdb) run