[comp.unix.questions] Getting PID of background process in shell script.

peter@ficc.uu.net (Peter da Silva) (03/25/90)

How about redirecting this to a more appropriate newsgroup, like
comp.unix.questions...?
-- 
 _--_|\  `-_-' Peter da Silva. +1 713 274 5180. <peter@ficc.uu.net>.
/      \  'U`
\_.--._/
      v

ag@amix.commodore.com (Keith Gabryelski) (03/29/90)

[Article cut down c.u.w, c.u.q, and c.l.c AND followups directed to
 comp.unix.questions]

In article <3074@auspex.auspex.com> hitz@auspex.auspex.com (Dave Hitz) writes:
>In a shell script I want to start a process in the background and then
>kill it at some later time.  To do this I want to save it's pid in a
>variable.

From your example (not shown) you seem to be using the bourne shell
which has the ``$!'' notation for the last background process
executed.

So a shell script of the form:

	sleep 10000 &			# Through in a background process.
	ps				# Ps will show us what is running.
	echo Sleeps PID is $!
	sleep 3
	echo Killing PID $!
	kill $!				# Kill the backgrounf process.
	ps				# We should see the sleep anymore.

Should be an example of what you are trying to do.

Pax, Keith
-- 
ag@amix.commodore.com        Keith Gabryelski          ...!cbmvax!amix!ag