Xref: utzoo comp.lang.c:27172 misc.misc:9386 Path: utzoo!attcan!uunet!snorkelwacker!usc!elroy.jpl.nasa.gov!jarthur!spectre.ccsf.caltech.edu!tybalt.caltech.edu!starr From: starr@tybalt.caltech.edu (Christopher H. Starr) Newsgroups: comp.lang.c,misc.misc Subject: Re: Getting PID of background process in shell script. Message-ID: <1990Mar24.024315.2115@spectre.ccsf.caltech.edu> Date: 24 Mar 90 02:43:15 GMT References: <3074@auspex.auspex.com> Sender: news@spectre.ccsf.caltech.edu Organization: California Institute of Technology Lines: 22 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 its pid in a >variable. > [... stuff deleted ...] >Anyone have a [clean] way to do this? >Dave Hitz home: 408-739-7116 >UUCP: {uunet,mips,sun,bridge2}!auspex!hitz work: 408-492-0900 Why not use the shell variable '$!' which is defined as the process number of the last process run in the background (in decimal)? In your script (which I assume is a Bourne shell script), you can have, for example, ______________________ a.out & PID=$! : ' ... do stuff ... ' kill $PID ______________________ I hope this helps. - Christopher Starr ( starr@tybalt.caltech.edu )