From owner-freebsd-bugs@FreeBSD.ORG Sun Sep 16 21:20:14 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B0B54106566B for ; Sun, 16 Sep 2012 21:20:14 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 9BB068FC08 for ; Sun, 16 Sep 2012 21:20:14 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q8GLKEZj035134 for ; Sun, 16 Sep 2012 21:20:14 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q8GLKEoC035120; Sun, 16 Sep 2012 21:20:14 GMT (envelope-from gnats) Date: Sun, 16 Sep 2012 21:20:14 GMT Message-Id: <201209162120.q8GLKEoC035120@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: bin/171427: sh(1): Hitting ^Z doesn't suspend jobs like expected X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Sep 2012 21:20:14 -0000 The following reply was made to PR bin/171427; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, yanegomi@gmail.com Cc: Subject: Re: bin/171427: sh(1): Hitting ^Z doesn't suspend jobs like expected Date: Sun, 16 Sep 2012 23:11:33 +0200 > [while : ; do netperf -cCjt TCP_STREAM -H 10.7.187.52 -l 10 -- -D; done > works strangely with ^C/^Z] For the case with ^C, I indeed deliberately fixed that for 9.0. For the case with ^Z, this is indeed a caveat that is complained about more frequently, and different shells handle it differently because POSIX leaves it vague. POSIX discusses suspending jobs (process groups), but a sequence or while loop is not a job. One workaround is to make it a job by placing parentheses around the loop. With most shells, this creates a new process group and job that can be suspended normally. An exception is ksh93 which attempts to execute the subshell in the same process; I do not like this but I think POSIX permits it (and in non-interactive or no-job-control mode it is fine to execute a subshell in that way). What sh does is return status 146 (128+SIGTSTP) and continue (so while netperf; do :; done will abort if ^Z'ed). What bash appears to do is break loops if something was ^Z'ed. What zsh appears to do is fork and continue the loop after the suspended process terminates. However, it gets $? wrong. Also, it needs a fair bit of code and changes to the shell environment after the suspension do not affect the parent. -- Jilles Tjoelker