a simple and portable solution :
echo "openocd" | at now #openocd starts now, but via the at daemon, not the current shell!
pid=$(ps -ef | grep "[o]penocd" | awk '{print $1}')
echo "openocd is running with pid: $pid"
gdb
Some portability caveats: ps options depends on the OS! you could instead use a variant of : { ps -ef || ps aux ;} | grep '[o]penocd | cut -f 1. at could not be available (weird, but this happens...). $(...) needs a not reallllly old shell, otherwise use backticks.