summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libc/sys/wait.212
-rw-r--r--sys/kern/kern_exit.c16
-rw-r--r--sys/sys/wait.h5
3 files changed, 28 insertions, 5 deletions
diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2
index f4dfe9d..c492cd6 100644
--- a/lib/libc/sys/wait.2
+++ b/lib/libc/sys/wait.2
@@ -99,6 +99,7 @@ equals the absolute value of
The
.Fa status
argument is defined below.
+.Pp
The
.Fa options
argument contains the bitwise OR of any of the following options.
@@ -121,8 +122,15 @@ due to a
.Dv SIGTTIN , SIGTTOU , SIGTSTP ,
or
.Dv SIGSTOP
-signal also have
-their status reported.
+signal also have their status reported.
+The
+.Dv WSTOPPED
+option is an alias for
+.Dv WUNTRACED .
+The
+.Dv WNOWAIT
+option keeps the process whose status is returned in a waitable state.
+The process may be waited for again after this call completes.
.Pp
If
.Fa rusage
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index f0866ed..b536d99 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -690,7 +690,7 @@ kern_wait(struct thread *td, pid_t pid, int *status, int options,
pid = -q->p_pgid;
PROC_UNLOCK(q);
}
- if (options &~ (WUNTRACED|WNOHANG|WCONTINUED|WLINUXCLONE))
+ if (options &~ (WUNTRACED|WNOHANG|WCONTINUED|WNOWAIT|WLINUXCLONE))
return (EINVAL);
loop:
if (q->p_flag & P_STATCHILD) {
@@ -741,11 +741,23 @@ loop:
sigqueue_take(p->p_ksi);
PROC_UNLOCK(q);
+ PROC_UNLOCK(p);
+
+ if (options & WNOWAIT) {
+
+ /*
+ * Only poll, returning the status.
+ * Caller does not wish to release the proc
+ * struct just yet.
+ */
+ sx_xunlock(&proctree_lock);
+ return (0);
+ }
+
/*
* If we got the child via a ptrace 'attach',
* we need to give it back to the old parent.
*/
- PROC_UNLOCK(p);
if (p->p_oppid && (t = pfind(p->p_oppid)) != NULL) {
PROC_LOCK(p);
p->p_oppid = 0;
diff --git a/sys/sys/wait.h b/sys/sys/wait.h
index e5691db..0e23c23 100644
--- a/sys/sys/wait.h
+++ b/sys/sys/wait.h
@@ -72,11 +72,14 @@
* indicates that the caller should receive status about untraced children
* which stop due to signals. If children are stopped and a wait without
* this option is done, it is as though they were still running... nothing
- * about them is returned.
+ * about them is returned. WNOWAIT only request information about zombie,
+ * leaving the proc around, available for later waits.
*/
#define WNOHANG 1 /* Don't hang in wait. */
#define WUNTRACED 2 /* Tell about stopped, untraced children. */
+#define WSTOPPED WUNTRACED /* SUS compatibility */
#define WCONTINUED 4 /* Report a job control continued process. */
+#define WNOWAIT 8 /* Poll only. Don't delete the proc entry. */
#if __BSD_VISIBLE
#define WLINUXCLONE 0x80000000 /* Wait for kthread spawned from linux_clone. */
OpenPOWER on IntegriCloud