From owner-freebsd-current@FreeBSD.ORG Fri Dec 9 14:21:03 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88EAD106566B for ; Fri, 9 Dec 2011 14:21:03 +0000 (UTC) (envelope-from Mark.Martinec+freebsd@ijs.si) Received: from mail.ijs.si (mail.ijs.si [IPv6:2001:1470:ff80::25]) by mx1.freebsd.org (Postfix) with ESMTP id 0FBF78FC18 for ; Fri, 9 Dec 2011 14:21:03 +0000 (UTC) Received: from amavis-proxy-ori.ijs.si (localhost [IPv6:::1]) by mail.ijs.si (Postfix) with ESMTP id 3T0G261vFBzGN11 for ; Fri, 9 Dec 2011 15:21:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ijs.si; h= message-id:content-transfer-encoding:content-type:content-type :mime-version:in-reply-to:references:user-agent:date:date :subject:subject:organization:from:from:received:received :received:vbr-info; s=jakla2; t=1323440461; x=1326032462; bh=qiy Rzf+i7L6Xgz1RghnZ9o8QYMx1aG2M/4AGt843t1Y=; b=bWSClRLaj10EkoJO0vf WYm9/GQUo3fsbF2+kdZ/YVJIdm+2sev1w4fGjf0WVXPAfI9Piz2g76SAwv8eigYH hIWMkmX7vhZw2FfhgAkIBC7RczXKUAz9HdXzA5TAzBPNlO587ap/hrJYknDZFH4r TDB0lxZYuYh8dRiC/LeVvhV0= VBR-Info: md=ijs.si; mc=all; mv=dwl.spamhaus.org; X-Virus-Scanned: amavisd-new at ijs.si Received: from mail.ijs.si ([127.0.0.1]) by amavis-proxy-ori.ijs.si (mail.ijs.si [127.0.0.1]) (amavisd-new, port 10012) with ESMTP id Dz2l_8mvIuDh for ; Fri, 9 Dec 2011 15:21:01 +0100 (CET) Received: from rozamunda.ijs.si (unknown [IPv6:2001:1470:ff80:0:225:90ff:fe11:b090]) by mail.ijs.si (Postfix) with ESMTP for ; Fri, 9 Dec 2011 15:21:01 +0100 (CET) Received: from neli.ijs.si (neli.ijs.si [193.2.4.95]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by rozamunda.ijs.si (Postfix) with ESMTPSA id F26BB21148C for ; Fri, 9 Dec 2011 15:21:00 +0100 (CET) From: Mark Martinec Organization: J. Stefan Institute To: freebsd-current@freebsd.org Date: Fri, 9 Dec 2011 15:21:00 +0100 User-Agent: KMail/1.13.7 (FreeBSD/9.0-PRERELEASE; KDE/4.7.3; amd64; ; ) References: <4EE1D951.2030509@gmail.com> In-Reply-To: <4EE1D951.2030509@gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201112091521.00680.Mark.Martinec+freebsd@ijs.si> Subject: Re: Bug in Perl script X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Dec 2011 14:21:03 -0000 Alexander, > I have a script that runs command tail with open descriptor. > After 30 seconds, I close descriptor. But descriptor not closed. > When script is closed tail is present in ps aux. >=20 > $log_file =3D path_to_log; > eval { > local $SIG{ALRM} =3D sub { die; }; > alarm (30); > open (LOG, "tail -F $log_file|") || die "=D0=A1an`t open logfile > \"$log_file\""; > while () { > *** > } > alarm (0); > }; > close (LOG); > print ("Ok\n"); > exit(0); >=20 > This code is good working in FreeBSD 8.2, but in FreeBSD 9.0 not working. I don't see any difference in this respect between 8.2 and 9.0. Even in 8.2 the spawned tail process stays alive until the moment when it tries to write its next line to a pipe - only then it aborts with 'Broken pipe'. On a busy log file this happens soon, on an idling log file this may take forever. You should abort the forked process when you no longer need it: my $log_file =3D '/var/log/mail.log'; my $pid; eval { local $SIG{ALRM} =3D sub { die "Time is up" }; alarm(10); $pid =3D open(LOG, "tail -F $log_file|"); $pid or die "Can't open logfile \"$log_file\": $!"; while () { print "HERE: $_"; } alarm (0); 1; } or do { alarm (0); print "Bail out: $@"; }; if ($pid) { print "Terminating process [$pid]\n"; kill('TERM',$pid); } close(LOG); print "Ok\n"; Mark