summaryrefslogtreecommitdiffstats
path: root/bin/sh/jobs.h
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/jobs.h
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/jobs.h')
-rw-r--r--bin/sh/jobs.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/bin/sh/jobs.h b/bin/sh/jobs.h
index c75c353..8bc1082 100644
--- a/bin/sh/jobs.h
+++ b/bin/sh/jobs.h
@@ -68,6 +68,7 @@ struct job {
char used; /* true if this entry is in used */
char changed; /* true if status has changed */
char foreground; /* true if running in the foreground */
+ char remembered; /* true if $! referenced */
#if JOBS
char jobctl; /* job running under job control */
struct job *next; /* job used after this one */
@@ -81,7 +82,6 @@ enum {
SHOWJOBS_PGIDS /* PID of the group leader only */
};
-extern pid_t backgndpid; /* pid of last background process */
extern int job_warning; /* user was warned about stopped jobs */
extern int in_waitcmd; /* are we in waitcmd()? */
extern int in_dowait; /* are we in dowait()? */
@@ -98,6 +98,8 @@ struct job *makejob(union node *, int);
pid_t forkshell(struct job *, union node *, int);
int waitforjob(struct job *, int *);
int stoppedjobs(void);
+int backgndpidset(void);
+pid_t backgndpidval(void);
char *commandtext(union node *);
#if ! JOBS
OpenPOWER on IntegriCloud