d26df42d19a04373629b6b8ad52328c7983af985
diff --git a/doc/reference/tmpl/reaper.sgml b/doc/reference/tmpl/reaper.sgml
deleted file mode 100644
index 92ed24c..0000000
--- a/doc/reference/tmpl/reaper.sgml
+++ /dev/null
@@ -1,25 +0,0 @@
-<!-- ##### SECTION Title ##### -->
-VteReaper
-
-<!-- ##### SECTION Short_Description ##### -->
-A singleton object which catches %SIGCHLD signals and converts them into
-GObject-style &quot;child-exited&quot; signals.
-
-<!-- ##### SECTION Long_Description ##### -->
-<para>
-Because an application may need to be notified when child processes
-exit, and because there is only one %SIGCHLD handler, the #VteTerminal
-widget relies on a #VteReaper to watch for %SIGCHLD notifications and
-retrieve the exit status of child processes which have exited.  When
-glib provides child_watch functionality, the #VteReaper merely acts as
-a proxy for glib's own functionality.
-</para>
-
-<!-- ##### SECTION See_Also ##### -->
-<para>
-
-</para>
-
-<!-- ##### SECTION Stability_Level ##### -->
-
-
diff --git a/doc/reference/vte-docs.sgml b/doc/reference/vte-docs.sgml
index 99a26b9..fcde0d6 100644
--- a/doc/reference/vte-docs.sgml
+++ b/doc/reference/vte-docs.sgml
@@ -4,7 +4,6 @@
 <!ENTITY nbsp "&#160;">
 <!ENTITY vte-VteTerminal SYSTEM "xml/vte.xml">
 <!ENTITY vte-vteaccess SYSTEM "xml/vteaccess.xml">
-<!ENTITY vte-VteReaper SYSTEM "xml/reaper.xml">
 <!ENTITY vte-caps SYSTEM "xml/caps.xml">
 <!ENTITY vte-termcap SYSTEM "xml/termcap.xml">
 <!ENTITY vte-trie SYSTEM "xml/trie.xml">
@@ -22,6 +21,5 @@
     <title>VTE</title>
     &vte-VteTerminal;
     &vte-vteaccess;
-    &vte-VteReaper;
   </chapter>
 </book>
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 5e3f524..f5bc514 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -125,22 +125,6 @@ VTE_TERMINAL_ACCESSIBLE_GET_CLASS
 </SECTION>
 
 <SECTION>
-<FILE>reaper</FILE>
-<TITLE>VteReaper</TITLE>
-VteReaper
-vte_reaper_get
-vte_reaper_add_child
-<SUBSECTION Standard>
-VTE_REAPER
-VTE_IS_REAPER
-VTE_TYPE_REAPER
-vte_reaper_get_type
-VTE_REAPER_CLASS
-VTE_IS_REAPER_CLASS
-VTE_REAPER_GET_CLASS
-</SECTION>
-
-<SECTION>
 <FILE>internals</FILE>
 <TITLE>Internals</TITLE>
 <SUBSECTION Private>
@@ -225,7 +209,6 @@ _vte_fc_defaults_cb
 _vte_iso2022_codeset_changed_cb_fn
 vte_regex_match
 
-VteReaperClass
 VteTerminalClass
 
 </SECTION>
diff --git a/doc/reference/vte.types b/doc/reference/vte.types
index e50bc5b..48b2253 100644
--- a/doc/reference/vte.types
+++ b/doc/reference/vte.types
@@ -4,8 +4,6 @@
 #include "vte.h"
 #include "vteversion.h"
 #include "vteaccess.h"
-#include "reaper.h"
 
 vte_terminal_get_type
 vte_terminal_accessible_get_type
-vte_reaper_get_type
diff --git a/src/Makefile.am b/src/Makefile.am
index 93c88de..651a62e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,9 +1,9 @@
 bin_PROGRAMS = vte
-pkginclude_HEADERS = pty.h reaper.h vte.h vteaccess.h vtetypebuiltins.h vteversion.h
+pkginclude_HEADERS = pty.h vte.h vteaccess.h vtetypebuiltins.h vteversion.h
 lib_LTLIBRARIES = libvte.la
 pkglib_PROGRAMS = interpret utf8echo nativeecho utf8mode iso8859mode slowcat vterdb
 pkglib_SCRIPTS = decset osc window
-EXTRA_PROGRAMS = buffer dumpkeys iso2022 pty reaper reflect-text-view reflect-vte ring mev ssfe table trie xticker vteconv vtetc
+EXTRA_PROGRAMS = buffer dumpkeys iso2022 pty reflect-text-view reflect-vte ring mev ssfe table trie xticker vteconv vtetc
 EXTRA_DIST = \
 	$(pkglib_SCRIPTS) \
 	vteseq-gen.c \
@@ -61,8 +61,6 @@ libvte_la_SOURCES = \
 	matcher.h \
 	pty.c \
 	pty.h \
-	reaper.c \
-	reaper.h \
 	ring.c \
 	ring.h \
 	table.c \
@@ -124,7 +122,7 @@ endif
 
 libvte_la_LDFLAGS = $(LDFLAGS) \
 	-version-info $(LIBVTE_LTVERSION) \
-	-export-symbols-regex "^vte_terminal_.*|^_vte_pty_.*|^vte_reaper_.*|_vte_debug_.*" \
+	-export-symbols-regex "^vte_terminal_.*|^_vte_pty_.*|_vte_debug_.*" \
 	@LIBTOOL_EXPORT_OPTIONS@ @LIBTOOL_FLAGS@
 libvte_la_LIBADD = $(LIBS) $(VTE_LIBS) $(X_LIBS) $(PCRE_LIBS) $(FT2_LIBS)
 
@@ -303,16 +301,6 @@ pty_SOURCES = \
 	pty.h
 pty_LDADD = $(LDFLAGS) $(LIBS) $(GLIB_LIBS)
 
-reaper_CFLAGS = $(GTK_CFLAGS) -DREAPER_MAIN
-reaper_SOURCES = \
-	debug.c \
-	debug.h \
-	marshal.c \
-	marshal.h \
-	reaper.c \
-	reaper.h
-reaper_LDADD = $(LDFLAGS) $(LIBS) $(GOBJECT_LIBS)
-
 vterdb_CFLAGS = $(GTK_CFLAGS) $(X_CFLAGS) -DVTERDB_MAIN
 vterdb_SOURCES = vterdb.c
 vterdb_LDADD = $(LDFLAGS) $(LIBS) $(GTK_LIBS)
diff --git a/src/reaper.c b/src/reaper.c
deleted file mode 100644
index dcc9d05..0000000
--- a/src/reaper.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright (C) 2002 Red Hat, Inc.
- *
- * This is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include "../config.h"
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <glib.h>
-#include <glib-object.h>
-#include <gtk/gtk.h>
-#include "debug.h"
-#include "marshal.h"
-#include "reaper.h"
-
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-#include <glib/gi18n-lib.h>
-
-
-static VteReaper *singleton_reaper = NULL;
-struct reaper_info {
-	int signum;
-	pid_t pid;
-	int status;
-};
-
-G_DEFINE_TYPE(VteReaper, vte_reaper, G_TYPE_OBJECT)
-
-static void
-vte_reaper_signal_handler(int signum)
-{
-	struct reaper_info info;
-	int status;
-
-	/* This might become more general-purpose in the future, but for now
-	 * just forget about signals other than SIGCHLD. */
-	info.signum = signum;
-	if (signum != SIGCHLD) {
-		return;
-	}
-
-	if ((singleton_reaper != NULL) && (singleton_reaper->iopipe[0] != -1)) {
-		info.pid = waitpid(-1, &status, WNOHANG);
-		if (info.pid != -1) {
-			info.status = status;
-			if (write(singleton_reaper->iopipe[1], "", 0) == 0) {
-				write(singleton_reaper->iopipe[1],
-				      &info, sizeof(info));
-			}
-		}
-	}
-}
-
-static gboolean
-vte_reaper_emit_signal(GIOChannel *channel, GIOCondition condition,
-		       gpointer data)
-{
-	struct reaper_info info;
-	if (condition != G_IO_IN) {
-		return FALSE;
-	}
-	g_assert(data == singleton_reaper);
-	read(singleton_reaper->iopipe[0], &info, sizeof(info));
-	if (info.signum == SIGCHLD) {
-		_vte_debug_print(VTE_DEBUG_SIGNALS,
-				"Reaper emitting child-exited signal.\n");
-		g_signal_emit_by_name(data, "child-exited",
-				      info.pid, info.status);
-	}
-	return TRUE;
-}
-
-#if GLIB_CHECK_VERSION(2,4,0)
-static void
-vte_reaper_child_watch_cb(GPid pid, gint status, gpointer data)
-{
-	_vte_debug_print(VTE_DEBUG_SIGNALS,
-			"Reaper emitting child-exited signal.\n");
-	g_signal_emit_by_name(data, "child-exited", pid, status);
-	g_spawn_close_pid (pid);
-}
-#endif
-
-/**
- * vte_reaper_add_child:
- * @pid: the ID of a child process which will be monitored
- *
- * Ensures that child-exited signals will be emitted when @pid exits.  This is
- * necessary for correct operation when running with glib versions >= 2.4.
- *
- * Returns: the new source ID
- *
- * Since 0.11.11
- */
-int
-vte_reaper_add_child(GPid pid)
-{
-#if GLIB_CHECK_VERSION(2,4,0)
-	return g_child_watch_add_full(G_PRIORITY_HIGH,
-				      pid,
-				      vte_reaper_child_watch_cb,
-				      vte_reaper_get(),
-				      (GDestroyNotify)g_object_unref);
-#endif
-	return VTE_INVALID_SOURCE;
-}
-
-static void
-vte_reaper_init(VteReaper *reaper)
-{
-	struct sigaction action;
-	int ret;
-
-	/* Open the signal pipe. */
-	ret = pipe(reaper->iopipe);
-	if (ret == -1) {
-		g_error(_("Error creating signal pipe."));
-	}
-
-	/* Create the channel. */
-	reaper->channel = g_io_channel_unix_new(reaper->iopipe[0]);
-
-#if GLIB_CHECK_VERSION(2,4,0)
-	if ((glib_major_version > 2) || /* 3.x and later */
-	    ((glib_major_version == 2) && (glib_minor_version >= 4))) {/* 2.4 */
-		return;
-	}
-#endif
-
-	/* Add the channel to the source list. */
-	g_io_add_watch_full(reaper->channel,
-			    G_PRIORITY_HIGH,
-			    G_IO_IN,
-			    vte_reaper_emit_signal,
-			    reaper,
-			    NULL);
-
-	/* Set the signal handler. */
-	action.sa_handler = vte_reaper_signal_handler;
-	sigemptyset(&action.sa_mask);
-	action.sa_flags = SA_RESTART | SA_NOCLDSTOP;
-	sigaction(SIGCHLD, &action, NULL);
-	_vte_debug_print(VTE_DEBUG_SIGNALS,
-			"Hooked SIGCHLD signal in reaper.\n");
-}
-
-static GObject*
-vte_reaper_constructor (GType                  type,
-                        guint                  n_construct_properties,
-                        GObjectConstructParam *construct_properties)
-{
-  if (singleton_reaper) {
-	  return g_object_ref (singleton_reaper);
-  } else {
-	  GObject *obj;
-	  obj = G_OBJECT_CLASS (vte_reaper_parent_class)->constructor (type, n_construct_properties, construct_properties);
-	  singleton_reaper = VTE_REAPER (obj);
-	  return obj;
-  }
-}
-
-
-static void
-vte_reaper_finalize(GObject *reaper)
-{
-	struct sigaction action, old_action;
-
-	/* Reset the signal handler if we still have it hooked. */
-	action.sa_handler = SIG_DFL;
-	sigemptyset(&action.sa_mask);
-	action.sa_flags = SA_RESTART | SA_NOCLDSTOP;
-	sigaction(SIGCHLD, NULL, &old_action);
-	if (old_action.sa_handler == vte_reaper_signal_handler) {
-		sigaction(SIGCHLD, &action, NULL);
-	}
-	_vte_debug_print(VTE_DEBUG_SIGNALS,
-			"Unhooked SIGCHLD signal in reaper.\n");
-
-	/* Remove the channel from the source list. */
-	g_source_remove_by_user_data(reaper);
-
-	/* Remove the channel. */
-	g_io_channel_unref(VTE_REAPER(reaper)->channel);
-
-	/* Close the pipes. */
-	close(VTE_REAPER(reaper)->iopipe[1]);
-	close(VTE_REAPER(reaper)->iopipe[0]);
-
-	G_OBJECT_CLASS(vte_reaper_parent_class)->finalize(reaper);
-	singleton_reaper = NULL;
-}
-
-static void
-vte_reaper_class_init(VteReaperClass *klass)
-{
-	GObjectClass *gobject_class;
-
-	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
-#ifdef HAVE_DECL_BIND_TEXTDOMAIN_CODESET
-	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
-#endif
-
-	klass->child_exited_signal = g_signal_new("child-exited",
-						  G_OBJECT_CLASS_TYPE(klass),
-						  G_SIGNAL_RUN_LAST,
-						  0,
-						  NULL,
-						  NULL,
-						  _vte_marshal_VOID__INT_INT,
-						  G_TYPE_NONE,
-						  2, G_TYPE_INT, G_TYPE_INT);
-
-	gobject_class = G_OBJECT_CLASS(klass);
-	gobject_class->constructor = vte_reaper_constructor;
-	gobject_class->finalize = vte_reaper_finalize;
-}
-
-/**
- * vte_reaper_get:
- *
- * Finds the address of the global #VteReaper object, creating the object if
- * necessary.
- *
- * Returns: the global #VteReaper object, which should not be unreffed.
- */
-VteReaper *
-vte_reaper_get(void)
-{
-	return g_object_new(VTE_TYPE_REAPER, NULL);
-}
-
-#ifdef REAPER_MAIN
-GMainContext *context;
-GMainLoop *loop;
-pid_t child;
-
-static void
-child_exited(GObject *object, int pid, int status, gpointer data)
-{
-	g_print("[parent] Child with pid %d exited with code %d, "
-		"was waiting for %d.\n", pid, status, GPOINTER_TO_INT(data));
-	if (child == pid) {
-		g_print("[parent] Quitting.\n");
-		g_main_loop_quit(loop);
-	}
-}
-
-int
-main(int argc, char **argv)
-{
-	VteReaper *reaper;
-	pid_t p, q;
-
-	_vte_debug_parse_string(getenv("VTE_DEBUG_FLAGS"));
-
-	g_type_init();
-	context = g_main_context_default();
-	loop = g_main_loop_new(context, FALSE);
-	reaper = vte_reaper_get();
-
-	g_print("[parent] Forking.\n");
-	p = fork();
-	switch (p) {
-		case -1:
-			g_print("[parent] Fork failed.\n");
-			g_assert_not_reached();
-			break;
-		case 0:
-			g_print("[child]  Going to sleep.\n");
-			sleep(10);
-			g_print("[child]  Quitting.\n");
-			_exit(30);
-			break;
-		default:
-			g_print("[parent] Starting to wait for %d.\n", p);
-			child = p;
-			g_signal_connect(reaper,
-					 "child-exited",
-					 G_CALLBACK(child_exited),
-					 GINT_TO_POINTER(child));
-			break;
-	}
-
-	g_print("[parent] Forking.\n");
-	q = fork();
-	switch (q) {
-		case -1:
-			g_print("[parent] Fork failed.\n");
-			g_assert_not_reached();
-			break;
-		case 0:
-			g_print("[child]  Going to sleep.\n");
-			sleep(5);
-			_exit(5);
-			break;
-		default:
-			g_print("[parent] Not waiting for %d.\n", q);
-			break;
-	}
-
-
-	g_main_loop_run(loop);
-
-	g_object_unref(reaper);
-
-	return 0;
-}
-#endif
diff --git a/src/reaper.h b/src/reaper.h
deleted file mode 100644
index ef1849b..0000000
--- a/src/reaper.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2002 Red Hat, Inc.
- *
- * This is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef vte_reaper_h_included
-#define vte_reaper_h_included
-
-
-#include <sys/wait.h>
-#include <signal.h>
-#include <glib.h>
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-struct _VteReaper {
-	GObject object;
-	GIOChannel *channel;
-	int iopipe[2];
-};
-typedef struct _VteReaper VteReaper;
-
-struct _VteReaperClass {
-	GObjectClass parent_class;
-	guint child_exited_signal;
-};
-typedef struct _VteReaperClass VteReaperClass;
-
-GType vte_reaper_get_type(void);
-
-#define VTE_TYPE_REAPER			(vte_reaper_get_type())
-#define VTE_REAPER(obj)			(G_TYPE_CHECK_INSTANCE_CAST((obj), \
-							VTE_TYPE_REAPER, \
-							VteReaper))
-#define VTE_REAPER_CLASS(klass)		G_TYPE_CHECK_CLASS_CAST((klass), \
-							     VTE_TYPE_REAPER, \
-							     VteReaperClass)
-#define VTE_IS_REAPER(obj)		G_TYPE_CHECK_INSTANCE_TYPE((obj), VTE_TYPE_REAPER)
-#define VTE_IS_REAPER_CLASS(klass)	G_TYPE_CHECK_CLASS_TYPE((klass), \
-							     VTE_TYPE_REAPER)
-#define VTE_REAPER_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), \
-								   VTE_TYPE_REAPER, \
-								   VteReaperClass))
-
-VteReaper *vte_reaper_get(void);
-int vte_reaper_add_child(GPid pid);
-
-G_END_DECLS
-
-#endif
diff --git a/src/vte-private.h b/src/vte-private.h
index 7e88d28..248b315 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -46,7 +46,6 @@
 #include "debug.h"
 #include "vteconv.h"
 #include "vtedraw.h"
-#include "reaper.h"
 #include "ring.h"
 #include "caps.h"
 
@@ -206,7 +205,7 @@ struct _VteTerminalPrivate {
 	guint pty_output_source;
 	gboolean pty_input_active;
 	GPid pty_pid;			/* pid of child using pty slave */
-	VteReaper *pty_reaper;
+	guint child_watch_source;
 
 	/* Input data queues. */
 	const char *encoding;		/* the pty's encoding */
diff --git a/src/vte.c b/src/vte.c
index 24e7c55..ffded1b 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -3102,67 +3102,62 @@ vte_terminal_handle_sequence(VteTerminal *terminal,
 	return ret;
 }
 
-/* Catch a VteReaper child-exited signal, and if it matches the one we're
- * looking for, emit one of our own. */
 static void
-vte_terminal_catch_child_exited(VteReaper *reaper, int pid, int status,
-				VteTerminal *terminal)
+vte_terminal_child_watch_cb(GPid pid, int status, VteTerminal *terminal)
 {
-	if (pid == terminal->pvt->pty_pid) {
-		_VTE_DEBUG_IF (VTE_DEBUG_LIFECYCLE) {
-			g_printerr ("Child[%d] exited with status %d\n",
-					pid, status);
+        VteTerminalPrivate *pvt = terminal->pvt;
+
+        g_assert (pid == pvt->pty_pid);
+
+        _VTE_DEBUG_IF (VTE_DEBUG_LIFECYCLE) {
+                g_printerr ("Child[%d] exited with status %d\n",
+                                pid, status);
 #ifdef HAVE_SYS_WAIT_H
-			if (WIFEXITED (status)) {
-				g_printerr ("Child[%d] exit code %d.\n",
-						pid, WEXITSTATUS (status));
-			}else if (WIFSIGNALED (status)) {
-				g_printerr ("Child[%d] dies with signal %d.\n",
-						pid, WTERMSIG (status));
-			}
+                if (WIFEXITED (status)) {
+                        g_printerr ("Child[%d] exit code %d.\n",
+                                        pid, WEXITSTATUS (status));
+                }else if (WIFSIGNALED (status)) {
+                        g_printerr ("Child[%d] dies with signal %d.\n",
+                                        pid, WTERMSIG (status));
+                }
 #endif
-		}
-		/* Disconnect from the reaper. */
-		if (terminal->pvt->pty_reaper != NULL) {
-			g_signal_handlers_disconnect_by_func(terminal->pvt->pty_reaper,
-							     vte_terminal_catch_child_exited,
-							     terminal);
-			g_object_unref(terminal->pvt->pty_reaper);
-			terminal->pvt->pty_reaper = NULL;
-		}
-		terminal->pvt->pty_pid = -1;
+        }
 
-		/* Close out the PTY. */
-		_vte_terminal_disconnect_pty_read(terminal);
-		_vte_terminal_disconnect_pty_write(terminal);
-		if (terminal->pvt->pty_channel != NULL) {
-			g_io_channel_unref (terminal->pvt->pty_channel);
-			terminal->pvt->pty_channel = NULL;
-		}
-		if (terminal->pvt->pty_master != -1) {
-			_vte_pty_close(terminal->pvt->pty_master);
-			close(terminal->pvt->pty_master);
-			terminal->pvt->pty_master = -1;
-		}
-
-		/* Take one last shot at processing whatever data is pending,
-		 * then flush the buffers in case we're about to run a new
-		 * command, disconnecting the timeout. */
-		if (terminal->pvt->incoming != NULL) {
-			vte_terminal_process_incoming(terminal);
-			_vte_incoming_chunks_release (terminal->pvt->incoming);
-			terminal->pvt->incoming = NULL;
-			terminal->pvt->input_bytes = 0;
-		}
-		g_array_set_size(terminal->pvt->pending, 0);
-		vte_terminal_stop_processing (terminal);
+        pvt->child_watch_source = 0;
+        pvt->pty_pid = -1;
+
+        /* Close out the PTY. */
+        _vte_terminal_disconnect_pty_read(terminal);
+        _vte_terminal_disconnect_pty_write(terminal);
+        if (pvt->pty_channel != NULL) {
+                g_io_channel_unref (pvt->pty_channel);
+                pvt->pty_channel = NULL;
+        }
+        if (pvt->pty_master != -1) {
+                _vte_pty_close(pvt->pty_master);
+                close(pvt->pty_master);
+                pvt->pty_master = -1;
+        }
 
-		/* Clear the outgoing buffer as well. */
-		_vte_buffer_clear(terminal->pvt->outgoing);
+        /* Take one last shot at processing whatever data is pending,
+          * then flush the buffers in case we're about to run a new
+          * command, disconnecting the timeout. */
+        if (pvt->incoming != NULL) {
+                vte_terminal_process_incoming(terminal);
+                _vte_incoming_chunks_release (pvt->incoming);
+                pvt->incoming = NULL;
+                pvt->input_bytes = 0;
+        }
+        g_array_set_size(pvt->pending, 0);
+        vte_terminal_stop_processing (terminal);
 
-		/* Tell observers what's happened. */
-		vte_terminal_emit_child_exited(terminal);
-	}
+        /* Clear the outgoing buffer as well. */
+        _vte_buffer_clear(pvt->outgoing);
+
+        /* Tell observers what's happened. */
+        vte_terminal_emit_child_exited(terminal);
+
+	g_spawn_close_pid (pid);
 }
 
 static void mark_input_source_invalid(VteTerminal *terminal)
@@ -3249,7 +3244,6 @@ _vte_terminal_fork_basic(VteTerminal *terminal, const char *command,
 	char **env_add;
 	int i, fd;
 	pid_t pid;
-	VteReaper *reaper;
 
 	/* Duplicate the environment, and add one more variable. */
 	for (i = 0; (envv != NULL) && (envv[i] != NULL); i++) {
@@ -3290,21 +3284,11 @@ _vte_terminal_fork_basic(VteTerminal *terminal, const char *command,
 		vte_terminal_set_pty (terminal, fd);
 
 		/* Catch a child-exited signal from the child pid. */
-		reaper = vte_reaper_get();
-		vte_reaper_add_child(pid);
-		if (reaper != terminal->pvt->pty_reaper) {
-			if (terminal->pvt->pty_reaper != NULL) {
-				g_signal_handlers_disconnect_by_func(terminal->pvt->pty_reaper,
-						vte_terminal_catch_child_exited,
-						terminal);
-				g_object_unref(terminal->pvt->pty_reaper);
-			}
-			g_signal_connect(reaper, "child-exited",
-					G_CALLBACK(vte_terminal_catch_child_exited),
-					terminal);
-			terminal->pvt->pty_reaper = reaper;
-		} else
-			g_object_unref(reaper);
+	        terminal->pvt->child_watch_source =
+                        g_child_watch_add_full(G_PRIORITY_HIGH,
+                                               pid,
+                                               (GChildWatchFunc)vte_terminal_child_watch_cb,
+                                               terminal, NULL);
 	}
 
 	/* Clean up. */
@@ -8258,11 +8242,8 @@ vte_terminal_finalize(GObject *object)
 	}
 
 	/* Stop listening for child-exited signals. */
-	if (terminal->pvt->pty_reaper != NULL) {
-		g_signal_handlers_disconnect_by_func(terminal->pvt->pty_reaper,
-						     vte_terminal_catch_child_exited,
-						     terminal);
-		g_object_unref(terminal->pvt->pty_reaper);
+	if (terminal->pvt->child_watch_source != 0) {
+                g_source_remove (terminal->pvt->child_watch_source);
 	}
 
 	/* Stop processing input. */
