summaryrefslogtreecommitdiffstats
path: root/bin/sh/expand.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-06-29 22:37:45 +0000
committerjilles <jilles@FreeBSD.org>2010-06-29 22:37:45 +0000
commit8fcbe1caf89944ec27f00e1265b29374fd3e05de (patch)
treefec6cbce2d09b1054b1fc671f8093cc73e9c8694 /bin/sh/expand.c
parent49f38732fcf51babc8f4ba652aa99ac2a78eeb4b (diff)
downloadFreeBSD-src-8fcbe1caf89944ec27f00e1265b29374fd3e05de.zip
FreeBSD-src-8fcbe1caf89944ec27f00e1265b29374fd3e05de.tar.gz
sh: Forget about terminated background processes sooner.
Unless $! has been referenced for a particular job or $! still contains that job's pid, forget about it after it has terminated. If $! has been referenced, remember the job until the wait builtin has reported its completion (either with the pid as parameter or without parameters). In interactive mode, jobs are forgotten after termination has been reported, which happens before primary prompts and through the jobs builtin. Even then, though, remember a job if $! has been referenced. This is similar to what is suggested by POSIX and should fix most memory leaks (which also tend to cause sh to use more CPU time) with long running scripts that start background jobs. Caveats: * Repeatedly referencing $! without ever doing 'wait', like while :; do foo & echo started foo: $!; sleep 60; done will still use a lot of memory and CPU time in the long run. * The jobs and jobid builtins do not cause a job to be remembered for longer like expanding $! does. PR: bin/55346
Diffstat (limited to 'bin/sh/expand.c')
-rw-r--r--bin/sh/expand.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 2b522ab..6c81224 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -818,7 +818,7 @@ varisset(char *name, int nulok)
{
if (*name == '!')
- return backgndpid != -1;
+ return backgndpidset();
else if (*name == '@' || *name == '*') {
if (*shellparam.p == NULL)
return 0;
@@ -891,7 +891,7 @@ varvalue(char *name, int quoted, int subtype, int flag)
num = shellparam.nparam;
goto numvar;
case '!':
- num = backgndpid;
+ num = backgndpidval();
numvar:
expdest = cvtnum(num, expdest);
break;
OpenPOWER on IntegriCloud