1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
29 #include <sys/types.h>
49 get_a_child (gint ttl)
55 PROCESS_INFORMATION pi;
58 memset (&si, 0, sizeof (si));
60 memset (&pi, 0, sizeof (pi));
62 cmdline = g_strdup_printf( "child-test -c%d", ttl);
64 if (!CreateProcess (argv0, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
69 CloseHandle (pi.hThread);
83 #endif /* G_OS_WIN32 */
87 child_watch_callback (GPid pid, gint status, gpointer data)
89 gint ttl = GPOINTER_TO_INT (data);
92 g_print ("child %d (ttl %d) exited, status %d\n", pid, ttl, status);
94 g_print ("child %p (ttl %d) exited, status %d\n", pid, ttl, status);
98 g_main_loop_quit (main_loop);
104 test_thread (gpointer data)
106 GMainLoop *new_main_loop;
109 gint ttl = GPOINTER_TO_INT (data);
111 new_main_loop = g_main_loop_new (NULL, FALSE);
113 pid = get_a_child (ttl);
114 source = g_child_watch_source_new (pid);
115 g_source_set_callback (source, (GSourceFunc) child_watch_callback, data, NULL);
116 g_source_attach (source, g_main_loop_get_context (new_main_loop));
117 g_source_unref (source);
120 g_print ("whee! created pid: %p (ttl %d)\n", pid, ttl);
123 g_print ("whee! created pid: %d (ttl %d)\n", pid, ttl);
126 g_main_loop_run (new_main_loop);
132 main (int argc, char *argv[])
136 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'c')
138 int ttl = atoi (argv[1] + 2);
143 /* Only run the test, if threads are enabled and a default thread
144 implementation is available */
145 #if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
146 g_thread_init (NULL);
147 main_loop = g_main_loop_new (NULL, FALSE);
149 system ("/bin/true");
152 g_thread_create (test_thread, GINT_TO_POINTER (10), FALSE, NULL);
153 g_thread_create (test_thread, GINT_TO_POINTER (20), FALSE, NULL);
155 g_main_loop_run (main_loop);