[ale] bash pid

Jim Kinney jim.kinney at gmail.com
Fri Apr 16 12:12:46 EDT 2010


I found the solution this using coproc (a bash builtin).

GNU bash manual - GNU Project - Free Software Foundation (FSF)
http://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses

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.

so I would do:

coproc mysleep do_sleep
my_sleep_pid=$mysleep_pid
do_monitoring_function_here...

On Wed, Mar 24, 2010 at 12:25 PM, Jim Kinney <jim.kinney at gmail.com> wrote:

> 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.
>
> For example:
>
> #!/bin/bash
>
> my_pid=$$  # get's the pid of the main script
>
> function do_sleep {
>  # sleeps in certain conditions
>  if [ <condition> ]; then sleep 2m; fi
> }
>
> for poo in $( <generated list of crap>); do
>  psql -c "vacuum freeze poo;"
>  do_sleep
> done
>
> 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's not making sense in the
> psql call case. Could run a ps |grep <cmd> and strip out the extra or even
> pidof <cmd> but all require putting things in a background state.
>
> --
> --
> James P. Kinney III
> Actively in pursuit of Life, Liberty and Happiness
>
>


-- 
-- 
James P. Kinney III
Actively in pursuit of Life, Liberty and Happiness
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100416/9a84a32c/attachment.html 


More information about the Ale mailing list