Re: X-connection after a fork

On Tue, 3 Oct 2000, Conrad Steenberg wrote:

> Hi
> Thanks for everyone that replied, it seems I'll have to rethink the
> problem a little :-)
> Cheers!
> Conrad

If its not too late for one last reply, following the Gnome code's 
example you could set the close-on-exec flag for all file descriptors
except stdin/out/err.  See gnome-libs/libgnome/gnome-exec.c for all the

For a simple example, take the buttons example program that comes with 
gtk+-devel-1.2.6  (on Red Hat anyway), its pretty easy to modify it to 
spawn (for example) Gimp,


#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>


/* Our usual callback function */
void callback( GtkWidget *widget,
               gpointer   data )
	pid_t pid;
	int open_max;
    g_print ("Hello again - %s was pressed\n", (char *) data);

	switch ((pid = fork()))
		case -1:
			g_print("error in fork\n");
		case 0:
			open_max = sysconf (_SC_OPEN_MAX);
			for (i = 3; i < open_max; i++)
				fcntl(i, F_SETFD, (long)FD_CLOEXEC);
			execlp("gimp", "gimp", NULL);
			g_print("child pid is %d\n", (int) pid);




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]