[comp.sys.sgi] shell script and child pid's

Dan Karron@UCBVAX.BERKELEY.EDU (01/26/91)

How can I catch the pid of a spawned process from sh ?

karron:~:181sh
# echo xxx &
xxx

# run in foreground, pid is not reported.

6649
# echo xxx > /dev/null &
6650
# run in background, pid is reported.

# xxx=`echo xxx > /dev/null &`
6652

# how do you get thd pid string into a shell variable ?

I know that you can run ps and recover the child pid from the parent pid,
but if the shell is telling you the pid, why not pick it up and use it ?
ps won't be able to tell you which child pid is the one you want if you
spawn a number is like-named children.

There must be a simple trick out there !
Cheers!

dan.

+-----------------------------------------------------------------------------+
| karron@nyu.edu (E-mail alias that will always find me)                      |
| Fax: 212 263 7190           *           Dan Karron, Research Associate      |
| . . . . . . . . . . . . . . *           New York University Medical Center  |
| 560 First Avenue           \*\    Pager <1> (212) 397 9330                  |
| New York, New York 10016    \**\        <2> 10896   <3> <your-number-here>  |
| (212) 263 5210               \***\_________________________________________ |
| Main machine: karron.med.nyu.edu (128.122.135.3) IRIS 85GT                  |
+-----------------------------------------------------------------------------+

NOTE PHONE NUMBER CHANGE: The Med Ctr has changed from 340 to 263 exchange.

rlb@lavalite.asd.sgi.com (Robert Brown) (01/27/91)

In article <9101252007.AA06669@karron.med.nyu.edu>, Dan
Karron@UCBVAX.BERKELEY.EDU writes:
|> 
|> How can I catch the pid of a spawned process from sh ?
|> 
|> I know that you can run ps and recover the child pid from the parent pid,
|> but if the shell is telling you the pid, why not pick it up and use it ?
|> ps won't be able to tell you which child pid is the one you want if you
|> spawn a number is like-named children.
|> 
|> There must be a simple trick out there !
|> Cheers!
|> 
|> dan.

The  built-in shell variable $! contains it:

$ sleep 60 &
1990
$ echo $!
1990
$

Bob Brown
------------------------------------------------------------------
Silicon Graphics, Inc.  Advanced Systems Division  415 335 7299