From owner-freebsd-questions@FreeBSD.ORG Fri Jan 23 23:04:55 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E98CF106568F for ; Fri, 23 Jan 2009 23:04:55 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: from fk-out-0910.google.com (fk-out-0910.google.com [209.85.128.189]) by mx1.freebsd.org (Postfix) with ESMTP id 74E8E8FC22 for ; Fri, 23 Jan 2009 23:04:55 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: by fk-out-0910.google.com with SMTP id f40so1583017fka.11 for ; Fri, 23 Jan 2009 15:04:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=06Mj6DrM3e5k8nwLxhDG9kI5ECJRRlzk7bJ2T6M55hQ=; b=AWjoUFmHqfVL0jYf8nxVsR+Ys3YvJnGNwyOlyQkB3OWiwCABKa7jCfjRI0C5Zh9WEZ /zn3TgpBqFxJAQzZie+YwM1seY7iwRNFYHKr+0rjUJpzqyjwZD8FppAoNwW/cOAa8O5T B/FPG0eRtckTNcCasX/dFwb1pfv5Wk1TeuoN0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=a4H2cxg8TGhR8zoozhPNH2uKQXjxhjQLQVBgBJOAdm8f2LlYhR17uC4VLd7x4FXqqu z8mcUVU/J6LX6otbZhZOrDAeRWB1Q6Ji7jbNT9FPP+2OmWlifXzyB3gNRMye3oqGggld BIuWov9lTRtRjRZSqujLw73E3aTYA6JVuvJ38= MIME-Version: 1.0 Received: by 10.181.206.7 with SMTP id i7mr33263bkq.57.1232751894469; Fri, 23 Jan 2009 15:04:54 -0800 (PST) In-Reply-To: <560f92640901231058i3c9e8645n6a30c74ec868ba87@mail.gmail.com> References: <560f92640901221241y4fc1620aree083a812c1f3c8d@mail.gmail.com> <26ddd1750901221333x5356f4f3l6b6410fc05d4e6d4@mail.gmail.com> <560f92640901221451j2e2b259bw1559a8c8d8912941@mail.gmail.com> <560f92640901221458y9409360n34904461fb2580e4@mail.gmail.com> <26ddd1750901221635k17230c7eudb1edc38c808eb83@mail.gmail.com> <560f92640901231058i3c9e8645n6a30c74ec868ba87@mail.gmail.com> Date: Fri, 23 Jan 2009 15:04:54 -0800 Message-ID: <560f92640901231504w5d218736p64241bbda7e9b65f@mail.gmail.com> From: Nerius Landys To: Maxim Khitrov Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org Subject: Re: shell scripting, how to auto-timeout? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jan 2009 23:04:56 -0000 I decided that I want the exec line at the end of the script because I want the exit code of the script to be the exit code of the Java process. I'm willing to live with the fact that the sleep thread will wait its full 3 seconds. So my final script is this: #!/bin/sh cd `dirname "$0"` CLASSPATH="mapgen.jar" export CLASSPATH THIS_SCRIPT_PROCESS="$$" sleep 3 && kill "$THIS_SCRIPT_PROCESS" > /dev/null 2>&1 && \ echo "Terminated infinite looping." 1>&2 & #SLEEP_PROCESS="$!" exec /usr/local/bin/java $*