Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gtk ---- fork() help~~~

0 views
Skip to first unread message

webper

unread,
May 9, 2002, 3:35:22 PM5/9/02
to
In clist I tried to fork() and append it in fork-child... but

always

Xlib: unexpected async reply (sequence 0x3b35)!

then what is done to do......

some sorcecode here

....


Jens.T...@physik.fu-berlin.de

unread,
May 9, 2002, 3:54:02 PM5/9/02
to

You should use the X graphic routines from only one process alone,
i.e. have one process being responsible for all the graphics stuff.
Otherwise probably each process must do its own graphic initialisation.

Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Jens.T...@physik.fu-berlin.de
_ | | | | | | AG Moebius, Institut fuer Molekuelphysik
| |_| | | | | | Fachbereich Physik, Freie Universitaet Berlin
\___/ens|_|homs|_|oerring Tel: ++49 (0)30 838 - 53394 / FAX: - 56046

Christoph Tapler

unread,
May 9, 2002, 5:47:04 PM5/9/02
to
Jens.T...@physik.fu-berlin.de wrote:

> webper <webp...@hotmail.com> wrote:
>> In clist I tried to fork() and append it in fork-child... but
>> always
>> Xlib: unexpected async reply (sequence 0x3b35)!
>> then what is done to do......

I had a similar problem.
You have to close the X-connection for the forked process. If you do not
close it, two processes send data to one socket. Here's a code-snipped,
which could give you a few hints: (I hope I am right ;-) )

Display *dpy = x11Display();
pid_t child = fork();
if (0 == child) {
// it's the child
::close(ConnectionNumber(dpy));
int res = execl( lpr_str.latin1() , arguments[0], arguments[1],
arguments[2], NULL);
} else
{
...........
}

...


--
cu
taps

Jens.T...@physik.fu-berlin.de

unread,
May 10, 2002, 4:55:54 AM5/10/02
to
Christoph Tapler <christoph.tapler@_gmx.net> wrote:
> I had a similar problem.
> You have to close the X-connection for the forked process. If you do not
> close it, two processes send data to one socket. Here's a code-snipped,
> which could give you a few hints: (I hope I am right ;-) )

> Display *dpy = x11Display();
> pid_t child = fork();
> if (0 == child) {
> // it's the child
> ::close(ConnectionNumber(dpy));
> int res = execl( lpr_str.latin1() , arguments[0], arguments[1],
> arguments[2], NULL);
> } else
> {
> ...........
> }

Well, you only get a problem if both processes use X functions, if one
of them refrains to do so I guess everything is fine. But I have a bit
of a problem with your close: For this to work corectly you must assume
that what ConnectionNumber returns is a valid file descriptor. From
my reading of the man page for XOpenDisplay() I guess, that this does
not always have to be the case, because the connection can be "through
some local inter-process communication protocol" and "Xlib uses whatever
it believes is the fastest transport". This leaves me in some doubt if
the connection number is guaranteed to be a valid file descriptor.

And, by the way, storing return value of execl() and friends does not
make too much sense, if it returns at all you can be sure it failed
and in this case you should call exit() or _exit() and not continue.
The parent won't see the value of 'res' anyway.

0 new messages