A nasty issue I never got around to solve.
If I feed the result from a command into the tail of a while loop, how do I reliably get the pid read also.
It is clear to me that the PID needs to be read exactly at time of executing the command as shown below in the code.
Although VarA does contain the result of Command1, there is no way I can find to have the PID associated with Command1 to be fed into the while loop and stored in VarB…
It must be possible as there is no other reliable way I can think of to get the PID of command1 in this case fed into a while loop.
You cannot calculate the PID from the parent pid which I see too often online… That is a recipe for disaster due to cycling and due to pid skipping of existing PIDs in use. You dont want to kill the wrong process, which is always possible doing that method.
So how do I get the loop below to read the pid associated with Command1 accurately.
while read VarA VarB
do
<Some Stuff>
done < <( Command1 && echo $! )
The above code is just an example of what I want to achieve, obviously ( Command1 && echo $! ) doesnt work and have to be changed but it explainst the intention well of p[assing both program output and PID.