I don't think there's a straightforward (and especially cross-platform) way for Geany to know the grandchild process of the shell that gets run by the terminal.
BTW, you can also have build commands run directly in the builtin terminal inside Geany, and also disable the run script (not needed since the terminal is permanently open). Personally I find this much more ergonomic.
![screenshot_2017-08-24_15-16-34](https://user-images.githubusercontent.com/181177/29691314-688ba42a-88df-11e7...)