aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/kill/kill.c10
-rw-r--r--bin/sh/jobs.c2
-rw-r--r--bin/sh/tests/builtins/Makefile1
-rw-r--r--bin/sh/tests/builtins/kill1.08
4 files changed, 19 insertions, 2 deletions
diff --git a/bin/kill/kill.c b/bin/kill/kill.c
index 2d41f7865e48..ab1701e03bdb 100644
--- a/bin/kill/kill.c
+++ b/bin/kill/kill.c
@@ -133,9 +133,15 @@ main(int argc, char *argv[])
for (errors = 0; argc; argc--, argv++) {
#ifdef SHELL
- if (**argv == '%')
+ if (**argv == '%') {
pid = getjobpgrp(*argv);
- else
+ /*
+ * Silently ignore terminated jobs, like the kernel
+ * silently ignores zombies.
+ */
+ if (pid == 0)
+ continue;
+ } else
#endif
{
pid = strtol(*argv, &ep, 10);
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index 1c0c6bd22d21..6e7791c905a4 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -645,6 +645,8 @@ getjobpgrp(char *name)
struct job *jp;
jp = getjob(name);
+ if (jp->state == JOBDONE)
+ return 0;
return -jp->ps[0].pid;
}
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
index 6f60f8493c0e..b76d6312342a 100644
--- a/bin/sh/tests/builtins/Makefile
+++ b/bin/sh/tests/builtins/Makefile
@@ -86,6 +86,7 @@ FILES+= hash3.0 hash3.0.stdout
FILES+= hash4.0
FILES+= jobid1.0
FILES+= jobid2.0
+FILES+= kill1.0
FILES+= lineno.0 lineno.0.stdout
FILES+= lineno2.0
FILES+= local1.0
diff --git a/bin/sh/tests/builtins/kill1.0 b/bin/sh/tests/builtins/kill1.0
new file mode 100644
index 000000000000..c1b85503848e
--- /dev/null
+++ b/bin/sh/tests/builtins/kill1.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+: &
+p1=$!
+: &
+p2=$!
+wait $p2
+kill %1