in reply to Re^3: how to kill background process when script exit?
in thread how to kill background process when script exit?

I just caught your third example there - and it works also:
$kid = open (FH, "exec java JavaApp 2> /dev/null |");
So then instead of the shell running the app, the shell becomes the app, so the pid is the same. clever.