#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <glib.h>

static void handler(GPid pid, gint status, void *unused)
{
        int exit_status;
        GError *err = NULL;

        if (fork() == 0) {
                g_spawn_command_line_sync("echo launch child", NULL, NULL, &exit_status, &err);
                printf("child is back\n");
		exit(0);
        }
}

int main(int argc, char **argv)
{
	GMainLoop *loop = NULL;
        int x;

	x = fork();
        if (x) {
		loop = g_main_loop_new(NULL, FALSE);
                g_child_watch_add(x, (GChildWatchFunc)handler, NULL);
		g_main_loop_run(loop);
        } /* child does nothing but exit */
        return 0;
}

