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
Just had the same issue. My solution:
process_1 | process_2 & PID_OF_PROCESS_2=$! PID_OF_PROCESS_1=`jobs -p`
Just make sure process_1 is the first background process. Otherwise, you need to parse the full output of jobs -l.
jobs -l