From ff9f2bb88e60e77e8b6d7670ec90651ac4ae5cec Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 30 Oct 2006 10:37:17 +0000 Subject: 22913: set $! on "bg" --- ChangeLog | 4 ++++ Doc/Zsh/params.yo | 3 ++- Src/jobs.c | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6dcee426..366feb200 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-10-30 Peter Stephenson + + * 22913: Doc/Zsh/params.yo, Src/jobs.c: set $! after a "bg", too. + 2006-10-27 Peter Stephenson * unposted: Completion/Unix/Command/_perforce: completion diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index bbe3354ce..8959130fd 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -477,7 +477,8 @@ The following parameters are automatically set by the shell: startitem() vindex(!) item(tt(!) )( -The process ID of the last background command invoked. +The process ID of the last command started in the background with tt(&), +or put into the background with the tt(bg) builtin. ) vindex(#) item(tt(#) )( diff --git a/Src/jobs.c b/Src/jobs.c index 509b9e843..5b42a45b0 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1789,9 +1789,21 @@ bin_fg(char *name, char **argv, Options ops, int func) case BIN_WAIT: if (func == BIN_BG) jobtab[job].stat |= STAT_NOSTTY; - if ((stopped = (jobtab[job].stat & STAT_STOPPED))) + if ((stopped = (jobtab[job].stat & STAT_STOPPED))) { makerunning(jobtab + job); - else if (func == BIN_BG) { + if (func == BIN_BG) { + /* Set $! to indicate this was backgrounded */ + Process pn = jobtab[job].procs; + for (;;) { + Process next = pn->next; + if (!next) { + lastpid = (zlong) pn->pid; + break; + } + pn = next; + } + } + } else if (func == BIN_BG) { /* Silly to bg a job already running. */ zwarnnam(name, "job already in background"); thisjob = ocj; -- cgit 1.4.1