Re: PATCH: subshell into a new process group
Bart Schaefer <[email protected]>
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAH+w=7YTMtY10GmrcPujdNDmNT-JmdDswgynxrw65v7ghbVTTg@mail.gmail.com> |
On Sat, May 9, 2026 at 4:44 PM Anthony Heading <[email protected]> wrote: > > On Sun, May 10, 2026, at 2:29 AM, Bart Schaefer wrote: > > Not at a shell right now but I'm pretty sure the way to do this is > > ( print this is a new pgrp ) &! > > I believe I'd found this only works in MONITOR mode Indeed. > For non-interactive shells, I don't think that & vs &! makes any > difference, it just affects whether the job escapes the job table and > thus avoids being SIGHUPed and so on. [...] 'disown' does feel like > the broad purpose is to push the child out of the nest. Hm, that raises an interesting point -- the "disown" builtin can't force the child to change process groups. That would mean &! gets a separate special meaning. > But it would seem intuitive that your idea should work. Do we imagine > anyone currently uses &! in a non-interactive shell and expects the > subshell would stay in the same process group? > > So maybe something like the attached? Aside: I'm not sure it matters, but other uses of setpgrp have 0L rather than just 0. Also, please don't use multibyte unicode in the comments (em-dash, I think?). I don't think it needs a new ESUB flag. I've tried several test cases and can't find any way in which the following results in materially different behavior (other than the intended). Anyone? With this, the process group has already been changed before "disown". If this change is applied, we might also want to consider adding $sysparams[pgid] to zsh/system. Apologies if this gets unfortunate line-wrapping. diff --git a/Src/exec.c b/Src/exec.c index 60075f254..2f044cb9a 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1099,6 +1099,8 @@ entersubsh(int flags, struct entersubsh_ret *retp) if (flags & ESUB_ASYNC) { settrap(SIGINT, NULL, 0); settrap(SIGQUIT, NULL, 0); + if (flags & ESUB_PGRP) + setpgrp(0L, 0L); if (isatty(0)) { close(0); if (open("/dev/null", O_RDWR | O_NOCTTY)) {