From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29598 invoked by alias); 4 Nov 2015 04:27:04 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37059 Received: (qmail 25769 invoked from network); 4 Nov 2015 04:27:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=secretsauce.net; h=cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=dP6hK b2dhKF4kWleFnNBzLwACg4=; b=Hm4OePCsTXHD3tlUNU9GyJkd8tF3d3vVLYo12 hRTAtYtHBIBaFoEt8vheqVrjDuEI1UJPU+xpIaGMjLMV3Vd4r/QteHi6+wepFYnH 3EzgZdL6QKrZFmRkU5Hu6uZiJGegkp/ShER2XJLesZ9neerGd87VX8UNX/yIy5qd 9p9wT4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=dP6hKb2dhKF4kWleFnNBzLwACg4=; b=pqv6U YrpbdqGhyLVD4Ua+amiwlePIfgsYDhn13LjdaHj/O4MuKOaR4U/+0bggdjG09V6O q7SuaoVkBx/lRgeHKmTehRKSIWsRorbXMOEM3G4fa+8GLS6xPJJ49cwABhPOjAao VrSH7sGkaJ5VP+aQuvx38IDOU6yx7FBHxLUZHM= X-Sasl-enc: +w5VVZ9dbLftHHoqRbBhkmE6LUrxwhD0h/tBYQ7Gpnde 1446611221 References: <87wpu0g19r.fsf@secretsauce.net> <151103201631.ZM19473@torch.brasslantern.com> From: Dima Kogan To: Bart Schaefer Cc: zsh-workers Subject: Re: Possible bug in signal handling In-reply-to: <151103201631.ZM19473@torch.brasslantern.com> Date: Tue, 03 Nov 2015 20:27:00 -0800 Message-ID: <87vb9ifkyz.fsf@secretsauce.net> MIME-Version: 1.0 Content-Type: text/plain Bart Schaefer writes: > On Nov 2, 2:10am, Dima Kogan wrote: > } > } I have a /tmp/tst.sh script: > } > } awk '{print; fflush()}' | \ > } perl -e 'BEGIN { $SIG{INT} = sub { $SIG{INT} = undef; }; } while(<>) {sleep 1;} sleep 10000;' > } > } I invoke this script thusly: > } > } $ seq 5000 | perl -nE 'say "xxx"; sleep(1)' | zsh /tmp/tst.sh > } > } So it's a mostly do-nothing pipeline. When the user hits Ctrl-C the > } first time, I expect everything but the inner zsh and the inner perl > } processes to die, and the outer zsh to NOT display another prompt until > } a second Ctrl-C. Instead I see everything except the inner perl die > } (inner zsh dies too), and the prompt is returned immediately. > > I'm able to get bash to orphan that perl process sometimes, too, just > not reliably. > > The difference seems to be that bash calls waitpid() whereas zsh uses > sigpause() and doesn't do the wait*() until the SIGCHLD arrives. The > order of arrival of the CHLD and INT signals may therefore determine > whether the shell continues waiting or not. > > Changing the script to this -- > > trap '' INT > { trap - INT; awk '{print; fflush()}'; } | \ > perl -e 'BEGIN { $g = getpgrp($$); print "$g\n"; $SIG{INT} = sub { > $SIG{INT} = undef; }; } while(<>) > {sleep 1;} sleep 10000;' > > -- gets both shells to wait for perl to exit before the script exits. Thanks for looking at this, Bart. I don't really understand this area in detail, but should those changes be necessary? Is it not a bug in zsh (and bash, I guess) that the perl process is orphaned?