From owner-freebsd-questions@FreeBSD.ORG Thu Jan 22 20:46:32 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 D15B01065675 for ; Thu, 22 Jan 2009 20:46:32 +0000 (UTC) (envelope-from sebastian.mellmann@net.t-labs.tu-berlin.de) Received: from mail.net.t-labs.tu-berlin.de (mail.net.t-labs.tu-berlin.de [130.149.220.252]) by mx1.freebsd.org (Postfix) with ESMTP id 921FA8FC18 for ; Thu, 22 Jan 2009 20:46:32 +0000 (UTC) (envelope-from sebastian.mellmann@net.t-labs.tu-berlin.de) Received: from [192.168.1.2] (g225032094.adsl.alicedsl.de [92.225.32.94]) by mail.net.t-labs.tu-berlin.de (Postfix) with ESMTP id 4819270015D8; Thu, 22 Jan 2009 21:46:31 +0100 (CET) Message-ID: <4978DB28.2040908@net.t-labs.tu-berlin.de> Date: Thu, 22 Jan 2009 21:46:32 +0100 From: Sebastian Mellmann User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: Nerius Landys References: <560f92640901221241y4fc1620aree083a812c1f3c8d@mail.gmail.com> In-Reply-To: <560f92640901221241y4fc1620aree083a812c1f3c8d@mail.gmail.com> 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: Thu, 22 Jan 2009 20:46:33 -0000 > The java process has the potential to run forever, and I want it to > run for at most 1 second then get killed. I could write a parent > script that somehow gets the PID of the child script, but the problem > is that the java program writes to standard out, the result of the > program is written to standard out. I also don't really want to share > a PID with a temporary file. > > So what I might do is this: > > /usr/local/bin/java PipeGenerator $* & > sleep 1 > > > What about using 'pidof' and then check if it gives you a PID and kill the process? > Also with the above code I would be waiting for 1 second even if the > java process finished sooner. But that is a penalty I'm willing to > pay, unless there is a more elegant solution. > > How do I do this? > Regards, Sebastian