Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to propagate SIGTERM to the foreground job, if any?



On 2024-04-19 13:06:12 -0700, Bart Schaefer wrote:
> On Fri, Apr 19, 2024 at 12:00 PM Vincent Lefevre <vincent@xxxxxxxxxx> 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.

No, this is a script. You can test with

#!/usr/bin/env zsh
setopt TRAPS_ASYNC
echo $$
trap "trap - TERM; kill %1 $$" TERM
xterm
echo end

and type "kill <pid>" with the <pid> output by the script. This
kills both xterm and the script (no "end" output). Without the %1,
xterm isn't killed.

This shows that one can get the associated job of the foreground
command.

> > But then, why does "kill %%" work?
> 
> It doesn't.

Indeed, it doesn't, but %1 works (this was what I actually tried,
and I thought I had tried %% too, which I actually did only with
${jobstates:+%%} I think).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




Messages sorted by: Reverse Date, Date, Thread, Author