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

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



On Fri, Apr 19, 2024 at 10:18 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
>
> How to propagate SIGTERM to the foreground job, if any?

Hm ... if there's a foreground job, it should be the process group
leader for the terminal (so as to receive TSTP and INT), so it might
work just to do "kill 0 TERM"

> setopt TRAPS_ASYNC
> trap "trap - TERM; kill ${jobstates:+%%} $$" TERM
>
> But it seems that $jobstates is not available in the trap.

It's not that $jobstates is not available, it's that the foreground
job isn't in the table at all.

% trap 'print -aC2 -r -- "${(@kv)jobstates}"' INT
% sleep 10 & sleep 2 & sleep 5
[1] 39824
[2] 39825
^C
1  running:-:39824=running
2  running:+:39825=running
%




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