Re: Can anyone help me with this code?
- From: Jan Jirmasek <jim ure cas cz>
- To: Carlos Toledo <sarek22 casal upc es>
- Cc: gtk-list gnome org
- Subject: Re: Can anyone help me with this code?
- Date: Wed, 6 Sep 2000 11:31:16 +0200 (CEST)
On Tue, 5 Sep 2000, Carlos Toledo wrote:
Hi!
I don't understand the reason why are you doing it (the creating new
process). If is it possible, you should avoid multithreading in a gtk
program. If you really need it, it should be enough to use threads in the
gtk program (see gtk faq).
In this case, I think, that you should call the gtk_exit() in
the last existing process, not in the newly created process - I'd rather
finish it in regular way. (exit()). When you call gtk_exit(), it should
deallocate all the resources used by gtk, and probably also close
connections between the gtk program and X server. That is probably the
reason for 'broken pipe', when the original process then wants to display
something ...
Jim
> 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
>
>
>
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]