Re: broken pipe
- From: gtk-perl-list andrew pimlott net
- To: bpmedley 4321 tv
- Cc: gtk-perl-list gnome org
- Subject: Re: broken pipe
- Date: Thu, 13 Jun 2002 19:07:14 -0400
On Thu, Jun 13, 2002 at 02:10:18AM -0400, bpmedley 4321 tv wrote:
I'm having some trouble getting one of my gtk perl programs to run. More
specifically, I'm having trouble when I try to fork() and use Gtk at the
same time. My main goal is to construct an app that does gui work in the
parent and extra work in the child. However, I'm getting the "Broken
pipe" error when I try and use Gtk after forking.
Interestingly, I noticed that the program works if I "init Gtk" *after*
doing the fork.
The problem is not the fork, per se. The problem is the exit(3).
It is a common problem with forking: Both processes think they
should clean up when they exit. In your case, gtk (or maybe it is
xlib or gdk?) calls shutdown(2) on the connection to X when the
child exits, so the connection is broken when the parent tries to
use it. You can see this clearly with strace (on Linux).
In general, you should make sure that objects are only destroyed by
one of the forks.
One solution, as you know, is to make sure gtk is initialized only
in one process, by forking before initializing. Another is to
prevent clean-up routines from running in the child by calling
_exit(2), aka POSIX::_exit.
gtk probably should have a way to tell it not to clean up in the
current process. That would be the ideal solution, because other
clean-ups (eg, for objects initialized in the child) could still
run.
Andrew
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]