Re: fork() and main_quit()

When running a Gtk2 GUI which forks another process (which doesn't deal
with the GUI at all, just communicates via pipes), I found that if I
call Gtk2->main_quit() in the parent, it freezes the GUI for up to 30
seconds and then exits. 

If you're communicating via pipes anyway, can't you send a command over the pipe
from the parent process to cause the child to exit? Surely that'd be easier than
setting up signal handlers in the child.

I should mention that I use "use Gtk2 -init;" before forking, so maybe
it gets confused because both parent and child have Gtk2 initialized? 


Can you fork in your startup? Usually I find it's easier to just use init_check;
for one thing, using init_check gives you the chance to produce a nice, clean
error. Like this:

      "The gtk2-perl bindings could not be initialized; we need them to run!\n"
      unless ( Gtk2->init_check );

In general, the earlier you can fork, the earlier you should fork. Forking
copies over the whole contents of your process, so if you have a lot of useless
state information, you're wasting possibly a significant amount of system
resources (unless you're just doing a fork-exec, where the state information
gets tossed out as soon as you exec anyway).

I've got a program that leaves children open after exiting gtk. However, they're
all exec'ed children, I don't know if that makes a difference.

You could of course try breaking up your Perl into multiple files and use exec
on the separated-out child code.

Dan Flemming

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