[kwlug-disc] Parent Processes
Colin Mackay
zixiekat at gmail.com
Tue Jan 25 14:05:24 EST 2011
That just leaves me with:
1 search.pl
1 search.pl
No PID.
My earlier way is working, even if it's a for loop.
for i in `pgrep laFind.pl`
do
# echo "Looking at PID: $i"
ppid=`grep 'PPid:' /proc/$i/status | cut -f2 -d":" | sed 's/[\t]//g'`
if [ $ppid -eq 1 ]
then
echo "Found parent PID: $i"
echo "Child PIDs: `ps -o pid --ppid %i | sed s/[\n]/,/g`
fi
Only issue I'm running into is removing newlines from a list and inserting a
comma. I have searched a lot for this and I swear I've done it before with
sed:
sed 's/\n/,/g'
But it doesn't work. Neither does \n\r, \r or using a $. Using the $ just
sticks a comma at the end of each line.
On Tue, Jan 25, 2011 at 1:11 PM, John Van Ostrand <john at netdirect.ca> wrote:
> ----- Original Message -----
> > Ah! /proc/<PID>/status and look for 1 under PPid:, when you find all
> > the ones that have to do with search.pl and have a 1 for PPid, we're
> > all set.
>
> Now that I'm back at a computer this would work too:
>
> ps -e -o "%P %c" | grep -E "^ +1 " | grep search.pl
>
> Then pipe through sed or cut to get just the PID.
>
> --
> John Van Ostrand
> CTO, co-CEO
> Net Direct Inc.
> 564 Weber St. N. Unit 12, Waterloo, ON N2L 5C6
> Ph: 866-883-1172 x5102
> Fx: 519-883-8533
>
> Linux Solutions / IBM Hardware
>
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20110125/98bef288/attachment.htm>
More information about the kwlug-disc
mailing list