Re: XForms: XForms/fork()/events

Steve Lamont (
Wed, 2 Jul 97 21:21:31 PDT

To subscribers of the xforms list from (Steve Lamont) :

> With this change the "Xlib: unexpected async ..." message doesn't appear
> anymore but I now get a different error.
> XIO: fatal IO error 2 (Bad file number) on X server ":0.0"
> after 1993 requests (1992 known processed) with 0 events remaining.
> Remember that the first things the child process does are to create a new
> form and to wait for the user to press a button. With the X connection
> closed the XForms commands probably won't work :-).

Ah. I was afraid of this.

Basically you can't do it. The problem is that there's no way to
disambiguate the communications on the file descriptor specifying the
TCP connection to the server. As the manual page for fork() says:

o The child process has its own copy of the parent's
descriptors. These descriptors reference the same under-
lying objects, so that, for instance, file pointers in
file objects are shared between the child and the parent,
so that an lseek(2V)) on a descriptor in the child pro-
cess can affect a subsequent read(2V) or write(2V) by the
parent. This descriptor copying is also used by the
shell to establish standard input and output for newly
created processes as well as to set up pipes.

You've also got all the X and XForms internal state and there's no way
to reinitialize this in a graceful manner. This isn't really an
XForms limitation as much as it is an Xlib limitation.

X11R6 provides support for multiple threaded applications, mostly in
the X Toolkit, Xt, but XForms is not Xt based, it's based on Xlib.
There is an Xlib function call XInitThreads() in R6. I don't have any
experience with it so I don't know of it'll do what you want. You may
need to spawn a POSIX thread rather than fork() a process to use it.
And of course it will only run on R6.

The O'Reilly _Programmer's Supplement for Release 6 of the X Window
System_ by Adrian Nye (ISBN 1-56592-089-9) covers these new calls.

My only suggestion is to redesign your application such that you only
spawn forms from a single process. Consider using an idle callback.

Maybe wiser heads than mine can come up with a solution.

To unsubscribe, send the message "unsubscribe" to or see
Xforms Home Page:
List Archive: