I found the solution this using coproc (a bash builtin).<br><br>GNU bash manual - GNU Project - Free Software Foundation (FSF)<br><a href="http://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses">http://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses</a><br>
<br>With coproc I could do exactly what I wanted: let the main script run the external and still have control over it directly. The array set up by coproc are great IO pipes to the externalized function(s) and the coproc_pid is directly available to the main script for monitoring.<br>
<br>so I would do:<br><br>coproc mysleep do_sleep<br>my_sleep_pid=$mysleep_pid<br>do_monitoring_function_here...<br><br><div class="gmail_quote">On Wed, Mar 24, 2010 at 12:25 PM, Jim Kinney <span dir="ltr">&lt;<a href="mailto:jim.kinney@gmail.com">jim.kinney@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I have a bash script that performs a sequence of tasks. I would like to be able to get the pid of the individual tasks for probable kill needs.<br>
<br>For example:<br><br>#!/bin/bash<br><br>my_pid=$$  # get&#39;s the pid of the main script<br>
<br>function do_sleep {<br> # sleeps in certain conditions<br> if [ &lt;condition&gt; ]; then sleep 2m; fi<br>}<br><br>for poo in $( &lt;generated list of crap&gt;); do<br> psql -c &quot;vacuum freeze poo;&quot;<br> do_sleep<br>

done<br><br>So I need to be able to get the pid of the sleep and the psql. $! will give the pid of a backgrounded shell process but that&#39;s not making sense in the psql call case. Could run a ps |grep &lt;cmd&gt; and strip out the extra or even pidof &lt;cmd&gt; but all require putting things in a background state. <br clear="all">

<br>-- <br><font color="#888888">-- <br>James P. Kinney III<br>Actively in pursuit of Life, Liberty and Happiness         <br><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>-- <br>James P. Kinney III<br>Actively in pursuit of Life, Liberty and Happiness         <br><br>