Here is my script called gdbwait:
#!/bin/sh
progstr=$1
progpid=`pgrep -o $progstr`
while [ "$progpid" = "" ]; do
progpid=`pgrep -o $progstr`
done
gdb -ex continue -p $progpid
Usage:
gdbwait my_program
Sure it can be written nicer but Bourne shell script syntax is painful for me so if it works then I leave it alone. 🙂
If the new process launches and dies too quickly, add 1 second delay in your own program for debugging.