How to get PID in backgrounded /bin/sh while loop?

Maarten Litmaath maart at cs.vu.nl
Wed Mar 21 08:12:20 AEST 1990


In article <MONTNARO.90Mar20094531 at spyder.crd.ge.com>,
	montnaro at spyder.crd.ge.com (Skip Montanaro) writes:
)...
)    while true ; do
)
)	... do some loopy stuff ...
)
)    done &
)
)how do you discover the process id of the backgrounded while loop process?
)
)A colleague suggested I write a small C program that just calls getppid(2),
)...

You could place such a utility in, say, /usr/local/bin for the time being.
I don't know what POSIX has to say about it, but somehow the child's pid
ought to be easily determined.  Instead of

	mypid=`getppid`

...I'd rather see something like

	mypid=$%

Nowadays the only alternative to the C program is:

	sh -c '
		pid=$$

		while :
		do
			# some loopy stuff with $pid
		done
	' &
--
 1) Will 4.5BSD have wait5()?         |Maarten Litmaath @ VU Amsterdam:
 2) Sleep(3) should be sleep(2) again.|maart at cs.vu.nl, uunet!mcsun!botter!maart



More information about the Comp.unix.questions mailing list