Consider the following simplified example:
my_prog|awk \'...\' > output.csv & my_pid=\"$!\" #Gives the PID for awk instead of for my_prog sleep 10 kill $my
With inspiration from @Demosthenex's answer: using subshells:
$ ( echo $BASHPID > pid1; exec vmstat 1 5 ) | tail -1 & [1] 17371 $ cat pid1 17370 $ pgrep -fl vmstat 17370 vmstat 1 5