For the shell script, I use /bin/bash for my scripts here.
With bash, the $BASHPID variable can be used to obtain the PID of a subshell (function), so you could use that. Eg. SUB_PID=$BASHPID

Next note: After invoking "kill" (which doesn't "kill" anything, it just sends a signal), your functions continue to execute and return data. If you don't want that to happen, then add an "exit 1" line after each "kill" line.

When I remove the "trap" line from the TestForBadProblem() function, your script appears to work just fine for me here. How about there?