Xref: utzoo comp.unix.wizards:21215 comp.unix.questions:20937 comp.lang.c:27304 Path: utzoo!attcan!uunet!cbmvax!amix!ag From: ag@amix.commodore.com (Keith Gabryelski) Newsgroups: comp.unix.wizards,comp.unix.questions,comp.lang.c Subject: Re: Getting PID of background process in shell script. Message-ID: <304@amix.commodore.com> Date: 28 Mar 90 21:49:20 GMT References: <3074@auspex.auspex.com> Reply-To: ag@amix.commodore.com (Keith Gabryelski) Followup-To: comp.unix.questions Organization: Commodore Amix Development Lines: 27 [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