Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!n8emr!uncle!donlash From: donlash@uncle.uucp (Donald Lashomb) Newsgroups: comp.unix.questions Subject: Re: Timeout on shell command. Message-ID: <1990Aug12.221658.27776@uncle.uucp> Date: 12 Aug 90 22:16:58 GMT References: Reply-To: donlash@uncle.UUCP (Donald Lashomb) Organization: U.N.C.L.E. Lines: 24 In article brister@decwrl.dec.com (James Brister) writes: >I'd like to have a shell script run a command, but if that command doesn't >finish in X seconds, then the script should kill it, if the command >finishes sooner then the script should immediately continue. Any ideas on >how one could achieve this? I'd approach it like this- #!/bin/sh # # run the command in the background # remember its process ID # sleep for X seconds # kill the background command --- note: if # the background command is finished, then # the kill will fail benignly. # command & cmdpid=$! sleep $X kill $cmdpid hope this helps -Don