[ale] bash pid

Richard Bronosky Richard at Bronosky.com
Sat Mar 27 21:57:22 EDT 2010


Don,
An easier pattern than that awk is:
grep '[u]niquestringofprocess'

The [] won't match itself.

On 3/27/10, Don Lachlan <ale-at-ale.org at unpopularminds.org> wrote:
> 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.
>
> Jim,
>
> Looking at your script and description, I don't understand what you're
> trying to do, except that you're not using background processes. So...
>
> In cases where you're launching a daemon, you can use your system's
> method for launching daemons.
>
> In Debian and Ubuntu, use start-stop-daemon
> In OpenSuSE and SLES, use startproc
> In CentOS and RHEL, use the functions in /etc/init.d/functions
>
> If you're looking for the PID of a foreground process, you cannot do
> that from the parent process. From a separate process, you do want
> 'ps' and 'awk':
>
> $ procpid=`ps -eo 'pid,args' | awk '/uniquestringofprocess/ && !/awk/
> {print $1}'`
>
> -Lachlan
>
>
>>
>> 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
>>
>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
>>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>

-- 
Sent from my mobile device

.!# RichardBronosky #!.



More information about the Ale mailing list