[NCLUG] Bashing lost children
Bryan Stillwell
bryan at bokeoa.com
Tue Apr 9 17:11:44 MDT 2002
Could you use "pidof sleep" to get what you want?
Or maybe "ps -s $$" with a combination of grep?
Otherwise I don't know where else you might get this information...
Bryan
On Tue, Apr 09, 2002 at 04:54:12PM -0600, Michael Dwyer wrote:
>No, no! Put away the pitch-forks and oil-soaked-rag torches!! I'm
>talking about child /processes/ in the bash shell!
>
>Okay, so you know how the shell variable $$ stands for the PID of the
>shell? Great. Now, what if you want to keep track of the PID of a
>process that the shell spawns. The shell is aware of the PID, since it
>echos it on the terminal:
>
> /bin/sleep 15 &
> [1] 30631
>
>I suppose I could even use some fancy AWK or SED to pull it out of jobs:
>
> jobs -l | awk '{print $2;}' -
> 30631
>
>But this seems strange to me -- isn't this PID stored somewhere useful?
>Or passed back somehow? The script below sort of explains what I want
>to do... Am I missing something horribly obvious?
>
>#!/bin/bash
>#
># This line stores the pid of the bash shell.
>echo $$ > /var/run/bash.pid
>
># Now... how do I get to the pid of the child that I create?
>/bin/sleep 100 &
>CHILD_PID=???????
>echo $CHILD_PID >/var/run/sleep.pid
>wait $CHILD_PID
>
>rm /var/run/bash.pid
>rm /var/run/sleep.pid
More information about the NCLUG
mailing list