From owner-freebsd-questions@FreeBSD.ORG Wed Feb 7 16:59:01 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 94EA516A402 for ; Wed, 7 Feb 2007 16:59:01 +0000 (UTC) (envelope-from asanjuan@bolsabilbao.es) Received: from correo-1.bolsabilbao.es (correo-1.bolsabilbao.es [212.8.77.215]) by mx1.freebsd.org (Postfix) with ESMTP id 1C5ED13C471 for ; Wed, 7 Feb 2007 16:59:00 +0000 (UTC) (envelope-from asanjuan@bolsabilbao.es) Received: from correo_6.bolsabilbao.es ([10.33.5.206]) by correo-1.bolsabilbao.es with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Feb 2007 17:58:59 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Class: urn:content-classes:message X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2826 Date: Wed, 7 Feb 2007 17:58:41 +0100 Message-ID: In-Reply-To: <20070207164634.GL37689@dan.emsphone.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Trapping signal from shell script... doesn't seem to work? thread-index: AcdK1+hcUHntaKw5SdCn7l7LZP41RQAAT3Lw From: "Aitor San Juan" To: Importance: normal Priority: normal X-OriginalArrivalTime: 07 Feb 2007 16:58:59.0787 (UTC) FILETIME=[431FE1B0:01C74AD9] X-ExchangeSecure-AntiSpam: valid(0) Subject: RE: Trapping signal from shell script... doesn't seem to work? 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: Wed, 07 Feb 2007 16:59:01 -0000 Dan, thanks a lot. I'll have a look at it. Regards. -----Mensaje original----- De: owner-freebsd-questions@freebsd.org [mailto:owner-freebsd-questions@freebsd.org]En nombre de Dan Nelson Enviado el: mi=E9rcoles, 07 de febrero de 2007 17:47 Para: Aitor San Juan CC: freebsd-questions@freebsd.org Asunto: Re: Trapping signal from shell script... doesn't seem to work? In the last episode (Feb 07), Aitor San Juan said: > I have written a Bourne shell script. This shell script invokes a > program written in the C language. >=20 > Below is basically the shell script source code. As you can see, the > C program is not invoked in the background, but in the foreground, so > the shell script doesn't finish until the C program has finished. >=20 > I want the shell script to trap TERM or INT signals, so when any of > these are raised, the shell script will try to send SIGTERM to the > program "myprog": Since you didn't background "myprog", the shell can't do anything until it returns, including signal processing. See the text at = http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#t= ag_02_11 There's a nice page about trap handling and shells at http://www3.cons.org/cracauer/bourneshell.html , which includes an example that does what you want: #! /bin/sh pid=3D onint() { kill $pid } trap onint SIGINT ./hardguy & pid=3D$! wait $pid ------------------- Dan Nelson dnelson@allantgroup.com ************ LEGEZKO OHARRA / AVISO LEGAL / LEGAL ADVICE *************=20 Mezu honek isilpeko informazioa gorde dezake, edo jabea duena, edota = legez babestuta dagoena. Zuri zuzendua ez bada, bidali duenari esan eta = ezabatu, inori berbidali edo gorde gabe, legeak debekatzen duelako = mezuak erabiltzea baimenik gabe.=20 -------------------------------------------------------------------------= - Este mensaje puede contener informaci=F3n confidencial, en propiedad o = legalmente protegida. Si usted no es el destinatario, le rogamos lo = comunique al remitente y proceda a borrarlo, sin reenviarlo ni = conservarlo, ya que su uso no autorizado est=E1 prohibido legalmente. -------------------------------------------------------------------------= - This message may contain confidential, proprietary or legally privileged = information. If you are not the intended recipient of this message, = please notify it to the sender and delete without resending or backing = it, as it is legally prohibited. *************************************************************************= *