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

int main(int argc, char **argv)
{
    gboolean	result;
    gchar	**spawn_argv;
    GPid	child_pid;

    if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'c')
    {
	/* I am test child process so loop forever. */
	for ( ; ; )
	    ;
	exit(1);
    }

    spawn_argv = g_new (gchar *, 3);
    spawn_argv[0] = g_strdup(argv[0]);
    spawn_argv[1] = g_strdup("-c");
    spawn_argv[2] = NULL;
  
    result = g_spawn_async(NULL,
			   spawn_argv,
			   NULL,
			   G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_SEARCH_PATH,
			   NULL,
			   NULL,
			   &child_pid,
			   NULL);

    printf("Child PID is: %d; check /proc/%d/fd/ for extra pipe.\n",
	   child_pid, child_pid);
    return 0;
}
