From owner-freebsd-questions@FreeBSD.ORG Thu Jan 22 22:51:33 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 29CB0106566B for ; Thu, 22 Jan 2009 22:51:33 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: from fk-out-0910.google.com (fk-out-0910.google.com [209.85.128.184]) by mx1.freebsd.org (Postfix) with ESMTP id A55CC8FC1E for ; Thu, 22 Jan 2009 22:51:32 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: by fk-out-0910.google.com with SMTP id f40so1010870fka.11 for ; Thu, 22 Jan 2009 14:51:31 -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=8EzaevK31xNd8Q29TUwn0R35kqnMeBcIJDjUg8Oiqy0=; b=lbC5Vah1PlxzLO9I6AelBVQBiA77p98agPAd7Qhz1M46dDdeNHH4/sEsUQiGNcRff6 XyzPMNmfLXf5mkjxt/TMwvw6pYnr68GDg3lEziXCztlS+FvsBTWkeIh7WEVVKnAPnHSC 5pnLQwf9rbaRHeyLBK0OEKq7I42KhQZ+V5L0s= 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=a/y8n8qDr1cImaQaG51eFmU43HIKLkgBQ8KVV0CiTWiLT+pqIXjVWQ1ITc1VuWXfL5 dUOtHKSqSgfiqS8x3yVSt+OgeINBZdskJeK37epg3wvZ814Blj7a4B3hynSMmDwbxYLq HdQEjAKJ9OtGuZ0JTOSRPVk2t1h4Wgk0UVyDo= MIME-Version: 1.0 Received: by 10.181.138.13 with SMTP id q13mr362508bkn.42.1232664691678; Thu, 22 Jan 2009 14:51:31 -0800 (PST) In-Reply-To: <26ddd1750901221333x5356f4f3l6b6410fc05d4e6d4@mail.gmail.com> References: <560f92640901221241y4fc1620aree083a812c1f3c8d@mail.gmail.com> <26ddd1750901221333x5356f4f3l6b6410fc05d4e6d4@mail.gmail.com> Date: Thu, 22 Jan 2009 14:51:31 -0800 Message-ID: <560f92640901221451j2e2b259bw1559a8c8d8912941@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: Thu, 22 Jan 2009 22:51:33 -0000 > #!/bin/sh > > java() > { > echo 'start' > sleep 5 > echo 'stop' > } > > sleep 1 && kill $$ & > java > kill $! >> { > echo 'start' > sleep 5 > echo 'stop' > } > > sleep 1 && kill $$ & > java > kill $! That is very genious. However, I had to add an "exec" to the parent script. Here is the test parent script, see the exec line below: #!/bin/sh cd `dirname "$0"` THIS_SCRIPT_PROCESS="$$" sleep 5 && echo "killing parent script, PID $THIS_SCRIPT_PROCESS" && kill "$THIS_SCRIPT_PROCESS" & TERMINATOR_PROCESS="$!" exec ./child_script echo "killing terminator process, PID $TERMINATOR_PROCESS" && kill "$TERMINATOR_PROCESS" And here is the child script "child_script": #!/bin/sh echo "start" while true; do # Infinite loop; use some CPU so that it's easy to find this in the output of top. echo "foo" > /dev/null done echo "stop" Without the "exec" in the parent script, the parent's child is not killed when the parent is killed.