Handle detach from sleeping or unresponsive processes
diff --git a/sysdeps/linux-gnu/events.c b/sysdeps/linux-gnu/events.c
index 021192f..b6c12ef 100644
--- a/sysdeps/linux-gnu/events.c
+++ b/sysdeps/linux-gnu/events.c
@@ -104,6 +104,8 @@
 	return each_qd_event(&event_process_not_reenabling, NULL);
 }
 
+int linux_in_waitpid = 0;
+
 Event *
 next_event(void)
 {
@@ -124,7 +126,11 @@
 		debug(DEBUG_EVENT, "event: No more traced programs: exiting");
 		exit(0);
 	}
+
+	linux_in_waitpid = 1;
 	pid = waitpid(-1, &status, __WALL);
+	linux_in_waitpid = 0;
+
 	if (pid == -1) {
 		if (errno == ECHILD) {
 			debug(DEBUG_EVENT, "event: No more traced programs: exiting");