[ale] bash pid

Jim Kinney jim.kinney at gmail.com
Wed Mar 24 12:25:57 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100324/24d25e5c/attachment.html 


More information about the Ale mailing list