PID of infinite loop run in background (&) in bash script
<p>I have simple bash script</p>

<pre><code>#!/bin/bash

(while true; do
        true;
        sleep 3
done) &amp;
</code></pre>

<p>How can I assign pid of this loop to variable, to kill process in future ? I try trap, but loop has own pid so I should know pid of loop running in background to kill it for example after SIGTERM.</p>