Can anyone help me with this code?



Hello, I have a problem with this code, when I create a child process
using gtk the program always dies with a broken pipe.
Here is the !#"!$% code:

#include <gtk/gtk.h>
#include <stdio.h>


void sistema (GtkWidget *widget, gpointer *data)
{
	int pid, index, w, estado, i=10;

	pid = fork ();

	switch (pid)
	{
		case 0:
		/* --- Codigo del hijo --- */
		for (index = 0; index < i ; index ++)
		{
			printf ("%d\n", index);
		}
		gtk_exit (0);
		break;

		default:
		
		while ( (w = wait (&estado) ) != pid && pid != -1);
		printf ("Proceso padre terminado.\007\n");
		break;
	}

}

int main ( int argc, char *argv[])
{
	GtkWidget *window;
	GtkWidget *boton;

	gtk_init (&argc, &argv);
		
	/* --- Creamos la ventana principal --- */
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_container_set_border_width(GTK_CONTAINER (window), 10);
	gtk_window_set_title (GTK_WINDOW (window), "Prueba proceso hijo");
	gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
	gtk_widget_set_usize (window, 200, 200);
	/* --- Creamos el boton --- */
	boton = gtk_button_new_with_label ("Proceso hijo");
	gtk_container_add (GTK_CONTAINER (window), boton);
	gtk_signal_connect (GTK_OBJECT (boton), "clicked", GTK_SIGNAL_FUNC (sistema), NULL);
	gtk_widget_show (boton);
	gtk_widget_show (window);
	gtk_main ();
	return 0;
}

Can someone tell me why the program fails?

			
thanks in advance.
Carlos

 





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