From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10554 invoked from network); 7 Nov 2022 19:34:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Nov 2022 19:34:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667849642; b=Y1XMvYOzr6sVNXu9jnXZRvW5yQ3M9mdM5M79actIvkPH9EmhDthyHdxGjahF1gBBpcat3E+IBS hw8Ge0FzTLkz+YkuFXhAse9NKNKs6h4OfuWMbAz/I/jwOD7AjFecbCXRzHp222zh9iffEySxo4 oL7aXk6jzhNngXpCq2k8mZ2w+1jP/IE/buDkkVdbRRxUbRi6e/nBUyXQ9F6MH6CfwJNNtdsWXD fZ27+es989150D4ZnAu2p+QQ/Vzfka1cMg3Ub2rbIl0lXSn6TYuLg+cQks5RoTQeErWvOlwZlN az7iY8AamRZjapotZDL9VQ+8BAoEZctjpmopLpZ7+RUYNQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f46.google.com) smtp.remote-ip=209.85.208.46; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1667849642; bh=8W80sGFxtUnD1QES4z8h6khte/VKUzGwnJUAQBm4wNM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=k99gSNUHr+W182+sXRTZNdP4+LpdIewUAMxZTWkMbWD8sfu3BUl2flAdqm6PVvRh6VaXp8L2cr e9Db5D0/P8DEmktnNf3JZkss4CRo5xrNcCGRAmqlEgv6TmpJst92jQwebFNCR3UDTUY14iL6Vg ji5nJbtR6VQwJPhn2kJPzIMujHcD6cT/v+wi8QDc/GBG5asn+9Dd85Sxn76CIf7OiF8C3rnN6k klZXLDlrRTTDiKCfL1a4wd2eFPJbi/i24D0ZGceZQvTdd/UFLj0YFbjgDQwPznYV6gd28u2pvG kom13MQaUtaKJHVOzqZTw/lWm3Ql2nE1LNeq9wdj8Y5ItA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=DRykVB9I0Lv48VeMIXHBkJS1AkhMwA9UHArwyf2DS4w=; b=FgkGtR/j4lN1afBJmsl+JeG4uF qn+5n+GXF0r+ufomvL5/HtKTK0GD3g/JJaWxLhI8a8M68hML8Z9HyeqHTOmAX4lUfaXFFHUwgIjoS d7FOY+FcI7JdkDPmykLOqAk537oPPXML5C8fsenb+QcBzrFziSF1AXEem0Oh2TW8L4/T1DOoCkN0B OM6xEfNZOGXlYZQLDuFY2zEcFv3q26UiSaf5d7pObwkJ2m7NgFN7gl7QFsS0+SYBOaBwI/v7JwBnx aJuUUdjJSEVsNcR/yTE+2R492BAtKP/Th0NRXjtgzWAWsIG8Pz6LGdDMuOtSo9pnp0lNek0LmA8TZ jeKBwCpQ==; Received: by zero.zsh.org with local id 1os7sf-000Nck-42; Mon, 07 Nov 2022 19:34:01 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f46.google.com) smtp.remote-ip=209.85.208.46; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f46.google.com ([209.85.208.46]:39595) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1os7s6-000NCw-Ms; Mon, 07 Nov 2022 19:33:28 +0000 Received: by mail-ed1-f46.google.com with SMTP id f7so19224272edc.6 for ; Mon, 07 Nov 2022 11:33:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DRykVB9I0Lv48VeMIXHBkJS1AkhMwA9UHArwyf2DS4w=; b=yk5DC/ulj4dze8OIJ+1Zc9c657e2lqSK5PRKrqCMbTVlOSscbczOlpbum/gjwSVDPF wcjqwQtydTAjf34cL1qWuvPY5v35771/HhZn3pFZw0Mv1a1Ud+QlcsGRB461u8RtboyC 1D4kjXTvvH+ohS6sIYG1p4SJSiYoPTWwzJubzPIWELynFQ1cHLTnA0alyN0A1S2iQqd+ SPFTLhrLQMwn+xxHXrF9M6M9swUfKmoS1eu7G2nkSRrJaJMVoqUmkPXjA9adFsjK0NIt 3vwdPmAtV5Z1jL+SYrcmsq8kJY05+moH6TNd/XtCCEcye+JFa8yzPsWyuifwg0Qv9hin Wh9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DRykVB9I0Lv48VeMIXHBkJS1AkhMwA9UHArwyf2DS4w=; b=zkOuxGab1EmUcJePd08RZc4IBPCLqRWSgik5M8LO5uuiJHw0pmRD5xR1ZoJ7p+NHWZ mKTIk2LAgpUC5SuLkbwC0Upbia9EpskoJUoQzgUS9LhQkMpGV3PBrdcQOxq4NR5ssJ4K wfHPE5EiPhmsv1QMbC0nJBNME7pc1v7hLF9xkan2fktKWBZ2L64lHn+hZ3wCZaMit0Pz /mDUOdb5Uo01FdEteE0Zjw37qrrRnG76zFHH9QJSXqP230dQ7V00QbOGmsgT5NUmDM6K 7q1X1MG0ZriRASZ4iVUzODHwYNIOQoYgm1PTiRwVfYrztCHYoCX+zMedw5TO9cu52WOx /RfQ== X-Gm-Message-State: ACrzQf3DyA7mEkJGbzilJ28YYfibJ5BrV1W9x4VqWmQQHUKXbzGWzXyI TI833LD3P9LEBwh+OZjFC0eM3wsmktJTcqBJkDU+JA== X-Google-Smtp-Source: AMsMyM607owYhhLBX+HRcADf+86pKzyLPpMImIMdikd5LJyLqQ5ALXrcEZ1jFjPDriD9/azyV2USz5m7cFtlGFS89mo= X-Received: by 2002:a50:d602:0:b0:463:a83b:6f89 with SMTP id x2-20020a50d602000000b00463a83b6f89mr37087556edi.366.1667849606032; Mon, 07 Nov 2022 11:33:26 -0800 (PST) MIME-Version: 1.0 References: <2FE96386-2D04-434F-AD2F-F08356B1AE04@kba.biglobe.ne.jp> <7BB37CE7-16A2-4079-956B-802E3FB4DC82@kba.biglobe.ne.jp> <0A744179-81FA-4405-857D-6FFBE8F8FA1E@kba.biglobe.ne.jp> In-Reply-To: <0A744179-81FA-4405-857D-6FFBE8F8FA1E@kba.biglobe.ne.jp> From: Bart Schaefer Date: Mon, 7 Nov 2022 11:33:14 -0800 Message-ID: Subject: Re: [PATCH] problem with 'ls | less' shell function To: Jun T Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 50901 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Mon, Nov 7, 2022 at 12:44 AM Jun T wrote: > > [1] ( zsh -fc 'print a few words; /bin/sleep 10'; ) Missing the | { head -n -1 } here, but I think still confirmed working? > [2] { sleep 10; sleep 11; } | { sleep 20; sleep 21; } > [3] dir () { ls | less; }; dir > > Now both ^C and ^Z/fg fork for [1], ^C works for [2], > and ^Z/fg works for [3] ({3] can't be killed by ^C but it's OK). > > But ^Z/fg still doesn't work for [2]; the pipeline never finishes. [...] > In the case of [2], the main zsh (zsh0) always fork() a subshell (zsh1) > for the left hand side of the pipe, and zsh1 fork/exec 'sleep 10'. > By hitting ^Z, zsh0 fork() another subshell (zsh2) for the right hand > side of the pipe, but it seems zsh2 is not causing the problem. Hmm. If I examine "pstree" I find: zsh(43919)---zsh(43978)---sleep(43980) 43978 is your "zsh2" and is busy-waiting with 100% CPU at #0 0x000055ca5bc4c042 in execpline (state=0x7ffc311ce770, slcode=4098, how=2, last1=0) at exec.c:1789 #1 0x000055ca5bc4abc3 in execlist (state=0x7ffc311ce770, dont_change_job=1, exiting=1) at exec.c:1444 #2 0x000055ca5bc477d7 in execcursh (state=0x7ffc311ce770, do_exec=1) at exec.c:450 43919 is "zsh1" and is here: #0 0x00007fcadf04045c in __GI___sigsuspend (set=0x7ffc311cd9b0) at ../sysdeps/unix/sysv/linux/sigsuspend.c:26 #1 0x000055ca5bcbf050 in signal_suspend (sig=17, wait_cmd=0) at signals.c:393 #2 0x000055ca5bc7c31a in zwaitjob (job=1, wait_cmd=0) at jobs.c:1629 > After 'fg', zsh1 (not zsh2) is using 100% of a CPU core, and > when 'sleep 10' exits it is left as "defunct" (not waited for). pstree for that zombie sleep shows it's a child of 43919 (zsh1) and hasn't been cleaned up yet because zsh1 is waiting on zsh2. zsh2 believes it's going to get signaled for the sleep, but it won't. > > 2022/10/22 6:22, Bart Schaefer wrote: > > > > On Fri, Oct 21, 2022 at 12:41 AM Jun T wrote: > >> > >> The subshell have missed the SIGCHLD? > > > > The subshell will never get the SIGCHLD, because it is a sibling of > > the pipeline, not its parent. > > Do you mean the subshell for the right hand side of the pipe? Yes, that is what I mean. The zombie sleep and zsh2 are siblings. > Strace output suggests that zsh1 does not receive SIGCHLD when > 'sleep 10' finishes. Maybe SIGCHLD is blocked?? (I'm not sure). #2 0x000055ca5bc7c31a in zwaitjob (job=1, wait_cmd=0) at jobs.c:1629 job=1 is zsh2: (gdb) p jobtab[1].procs[0] $2 = {next = 0x55ca5dca7690, pid = 43978, waitjob() in zsh1 will never return because zsh2 is in an infinite loop waiting for a child that doesn't exist. > zsh1 is repeatedly calling hasprocs(list_pid_job) at line 1790 in > exec.c: This is actually zsh2. As you noted, hasprocs() returns zero, so we fall through to 1902 else if (subsh && jn->stat & STAT_STOPPED) 1903 thisjob = newjob; 1904 else 1905 break; The condition at 1902 is true because jn->stat refers to the zombie sleep, which WAS stopped when zsh2 was forked (but is not actually even a job of this new subshell). So we go around the loop again at 1778 for (; !nowait;) { When zsh2 was forked during "sleep 20" , we should have hit this 1899 break; so we must have re-entered at line 1778 after starting the "sleep 21" and are now incorrectly waiting for the left side of the pipeline.