From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id A357521E36 for ; Fri, 19 Apr 2024 22:07:13 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713557233; b=fVe08BdOmq7aAFZtNYjnfXuByL6S1zMVpXA63HM8ENxGJUFemROSC3odeBC08oTVGPbHp9j7Nn cYi65iUwraLbzs3IiZVwUN90YUXTeBCBoXwtMZFJjDKdJntDqBYcagnAKtbl5yM2NKJ74mSdzu Iz8pMDytHTEtu96Osqcq2BPPPLdwZcdZYYBSvqp1ICfrvG4jGB3fIgktJQ6BTTsUbLTVt6wBDU o3skvrrxWjN4YfdTTFgPl7mmEHv79XJ4PuP2g3wlOSjmUj11/H8Gn46CzdIMpQ/S/QiuL6lNZZ 46ImyT+DhD1JNuuZ9lfm3aDXbNRmqcd90rBLNxoDpndP2A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f54.google.com) smtp.remote-ip=209.85.167.54; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 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=1713557233; bh=/Kvk8bsd0jZLWCf66qZyGQhQAjnxNQ2en9EpUAXLbqE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=MXj3X+rKhJTw63k7Ty98B1LRIeSmtNosO+jnSXk5dWJpHgZHAg+IoZ0jU7xHmsFw9lbbbkqDvh gjtp7c3u4mX/r3IIOae7r2smOpNFQf/CIsWuwkckBMv/BJ7pmapYAN9Gxl/Up/yQOmmpnVpjZs k6dF9ENaE7m0uBkpLLf5xdqfFvXS+pIbkyM61K4EMRey5RI7yEVqMpQUu+ScdGEY4Rp9a6FxPg fRjmEc2PP9MqP2CunMfRLdLyUAz0iG0NVkWFHjE69TBmnfbVIm4+O2+8UICl6qfy4qBteuuui3 23TfdLseODuzqMynQMAOUNLJw1P3RktNQn953Xp3yjgIbQ==; 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-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=lYpBTBeHpsCUAFkU1J29NVw+dQzsOqbIf5gnK7z08AU=; b=lNusAqm0q9pBjYmemDE3lM0K48 xV2VqoZ3EKfWL9oG3epMdyLT8wg9w75kJCjPoOz9F9ifXI3PoORnmfIcQ2nym8OoCs/Zrb49rIMPP FrlcupZgq3Hf3bWBIjL5eSScO2HMRW0ZA6PuoAT8y26Kr/WdtXtXCBzZWIGG3JEgujRl6mNn7Agb6 rhFPRhkkVR4cGD7i8ntELuapH8cUoW9Jq8M0JviV+1iHirbPBqgzR/58pfXwyeZ65yLoSCJUtP/LA prNI2jyI2D3FkVRN47Lci7N9deJ7DOUpZIsmEYa+oawYAWzGDb2c/04UQDDBGO4dyNTyC+K6MohCu +g5Q+cOA==; Received: by zero.zsh.org with local id 1rxuVs-000HgC-T8; Fri, 19 Apr 2024 20:07:12 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f54.google.com) smtp.remote-ip=209.85.167.54; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-lf1-f54.google.com ([209.85.167.54]:55445) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rxuV7-000GvZ-5o; Fri, 19 Apr 2024 20:06:26 +0000 Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-51acc258075so1061793e87.2 for ; Fri, 19 Apr 2024 13:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1713557184; x=1714161984; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lYpBTBeHpsCUAFkU1J29NVw+dQzsOqbIf5gnK7z08AU=; b=Ukf9F0M1gGW8AlEjBaMl5MrKbkjT+GCv8xnKAIxkchspQKwDC1dcAypwxKjWRe9vTt RqWU1w0NcoMbjlOw/+zUCGkLHu5ow8eJleAnrGprrBKYoWr7BqOudY4ZNyGyDAEGMHUJ jOEk7efeM8enKO07ZO0yBYNOTHIZ3fLVuwKT+iLzVibuWelxQnHT0ES9JghLnVgIsH+h jK6Ubug72oq4n8eiwilln3TtPp1ad3T1AXs7+CZ423aND7By05vvO1w4lfAAttLVg34z TdyrdMTcI8HRsV3dDRg7BLkBcJ0llzvSVr/4FX9pIHYCIuBI/68Vl4KiU6fUD6C0dA6D PxVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713557184; x=1714161984; h=content-transfer-encoding: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=lYpBTBeHpsCUAFkU1J29NVw+dQzsOqbIf5gnK7z08AU=; b=VAk5UiIRl8OfcLhr+1ViqI9nNyJL4oIwMMD0XRcs2qYkvU2QRwqaMHY8+WWPlg8nj8 BooHWNi+xhlpdDw6ETwE0I0Md2WtOfXZv8+poaNa7reXc/N3nQ2qwogjx42WvE1u3fHY QQDc0WcnoXzFFru28IBcgn07VhWe2Cbl7paxgNpwAi9YO2ZU0uUJA8Blywam4F6aSc4Y WFhWP/atBANEF5KDAD1KVgPlhF7T5al7IK4RjixTPhwmNYqMRwzGTk1krL1KQxIt9mmx pcskR2/9Gb/zrbfva+WoHvSxRjM0StZQAdYI9vgzOAdFeOEHZaWGZdqRcjI0L/igOekG uKTw== X-Gm-Message-State: AOJu0YzafqCxb7gbfsq8VaoHo/eaI7WU2n0EtdRf+dlmqR6wB/mFnlj5 pD7vVHjbqq6KbiYQe08io1zRgLilMqPdUEYIyzJmpenIuqnf7SVfs4uU58oyTNlRm57OYo+JDFk EHLIGe/DfskrziYgP3GU36OyYRdYn6zmns5WHYbJnVcOoLPKTgw== X-Google-Smtp-Source: AGHT+IFgZLKvuoQBRlVkjCEmOdUTnnEDkuO4wL1h0QDqAhMAje7qKqUNcMIgyl7rPjuTKkbNAx1GFpiBuDSZ+01STaA= X-Received: by 2002:a05:6512:48c:b0:51a:cfca:ca3f with SMTP id v12-20020a056512048c00b0051acfcaca3fmr1191910lfq.36.1713557183774; Fri, 19 Apr 2024 13:06:23 -0700 (PDT) MIME-Version: 1.0 References: <20240419171752.GA48158@cventin.lip.ens-lyon.fr> <20240419190027.GA109916@joooj.vinc17.net> In-Reply-To: <20240419190027.GA109916@joooj.vinc17.net> From: Bart Schaefer Date: Fri, 19 Apr 2024 13:06:12 -0700 Message-ID: Subject: Re: How to propagate SIGTERM to the foreground job, if any? To: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29838 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Fri, Apr 19, 2024 at 12:00=E2=80=AFPM Vincent Lefevre wrote: > > I don't understand why you are saying that "it should be the process > group leader for the terminal". This is not true in my case (the > leader is some ancestor) I don't understand how you're determining that the leader is an ancestor. That you have job control at all implies this is an interactive shell. When zsh starts interactively, it attaches to the TTY and makes itself the group leader. Subsequently, each time a foreground job is started, zsh attaches that to the TTY and makes it a new group leader, only reclaiming the TTY after the foreground job exits. If it did not do this, ^Z and ^C would not work. The only way for an "ancestor" of the job you want to TERM to be the group leader is if the job zsh started has subsequently forked again, in which case zsh doesn't have any knowledge or control of the "grandchild". That still doesn't mean that "kill 0" from the zsh process would kill the desired process group, I didn't actually try it. > On 2024-04-19 11:30:35 -0700, Bart Schaefer wrote: > > > > It's not that $jobstates is not available, it's that the foreground > > job isn't in the table at all. I was misled there by trying to use INT. The current job is reaped before the trap runs. > But then, why does "kill %%" work? It doesn't. % setopt trapsasync % trap 'print -raC2 -- ${(kv)jobstates}' TERM % (sleep 2 ; kill -TERM $$) & sleep 10 & sleep 3 & sleep 5 [1] 40302 [2] 40303 [3] 40305 1 running::40302=3Drunning 2 running:-:40303=3Drunning 3 running:+:40305=3Drunning 4 running::40306=3Drunning [1] done ( sleep 2; kill -TERM $$; ) [3] + done sleep 3 % [2] + done sleep 10 So in the above, job #4 would be the foreground job, but %+ (equivalent to %%) is job #3. The foreground job has no % shortcut. Further evidence: % (sleep 2 ; kill -TERM $$) &! sleep 10 1 running::40317=3Drunning % trap 'print -- ${jobstates:+SET}' TERM % (sleep 2 ; kill -TERM $$) &! sleep 10 SET % trap 'trap -- TERM; kill ${jobstates:+%%}' TERM % (sleep 2 ; kill -TERM $$) &! sleep 10 kill: no current job %