[comp.windows.x] Resources & Forking

gah@arnor.uucp (11/29/90)

Two questions...

1)  Is it possible to use X to read an X resource files without 
    being connected to a server?  If it is possible, how would 
    I do it??  I am currently using r3 & Motif 1.0.  If it makes
    a difference, can r4 or r5 do such stuff .. but not r3??

2)  If I open a display, then fork I presume both processes are
    sharing a connection to the server.  If one process only 
    wishes to read X resource files is there any problem with
    not explicitly synchronizing the processes?  Or does any 
    database operation require server contact?

thx, g

argv@turnpike.Eng.Sun.COM (Dan Heller) (11/29/90)

In article <1990Nov28.191838.4990@arnor.uucp> gah@ibm.com (Gary Hoffman) writes:
> 1)  Is it possible to use X to read an X resource files without 
>     being connected to a server?
No.  You must be connected to the server in order for the Xlib routines
to access the database associated with it (you can have a resource file
unique to every server).

> 2)  If I open a display, then fork I presume both processes are
>     sharing a connection to the server.
Nope.  Just the parent.  The child's connection *must* be closed.
You can reopen a -new- connection to the server and rebuild widgets
or do whatever you want.  I submitted a program called "vines" to
comp.sources.x several months ago which demonstrates this.  Basically,
it just sits there and forks allowing each child to draw colored vines
all over your screen.  If you are using Motif to do things, your child
process will have to build those widgets specific to that process.
Thus, it is best to fork early in a program since forking causes the
entire dataspece to be copied.  Since running X programs can be large,
your forked process should try to do whatever it can quickly and get
out soon.

> If one process only 
>     wishes to read X resource files is there any problem with
>     not explicitly synchronizing the processes?  Or does any 
>     database operation require server contact?

None of this will work.
--
dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.

mikel@teda.UUCP (Mikel Lechner) (11/30/90)

argv@turnpike.Eng.Sun.COM (Dan Heller) writes:

>In article <1990Nov28.191838.4990@arnor.uucp> gah@ibm.com (Gary Hoffman) writes:

>> 2)  If I open a display, then fork I presume both processes are
>>     sharing a connection to the server.
>Nope.  Just the parent.  The child's connection *must* be closed.
>You can reopen a -new- connection to the server and rebuild widgets
>or do whatever you want.

Actually the child process could keep the connection, but in this case the
parent should close it's connection and obtain a new connection to the
X server.  Both cannot use the same connection.

Also, if the child keeps the connection it cannot "exec" a new program
and keep the connection, since this would almost certainly confuse the
client code in the new program.


-- 
Mikel Lechner			UUCP:  teda!mikel
Teradyne EDA, Inc.
5155 Old Ironsides Drive	| If you explain so clearly that nobody
Santa Clara, Ca 95054		| can misunderstand, somebody will.

mouse@LARRY.MCRCIM.MCGILL.EDU (12/03/90)

> 1)  Is it possible to use X to read an X resource files without being
>     connected to a server?

Yes, provided you really mean "file".

>     If it is possible, how would I do it??

The R4 way would be to use...

	To retrieve a database from disk, use XrmGetFileDatabase.
	
	XrmDatabase XrmGetFileDatabase(filename)
	     char *filename;
	
	filename  Specifies the resource database file name.

I don't know whether R3 is capable of similar things, though I would
assume it is.

> 2)  If I open a display, then fork I presume both processes are
>     sharing a connection to the server.

(I assume you're using UNIX.)  Yes.

>     If one process only wishes to read X resource files is there any
>     problem with not explicitly synchronizing the processes?  Or does
>     any database operation require server contact?

As you may have gathered from the above and from other postings, server
access is not necessary for reading resource files.  Leaving the
connection open in both parent and child will not harm anything,
*provided* that only one of the two processes ever tries to do anything
with it after the fork.  (Two processes both trying to use the same
server connection will almost certainly get Xlib in a hopelessly
confused state.  You don't want to do it[%].)

[%] Unless, of course, you're willing to take on the task of putting
    the necessary synchronization code into Xlib.  This would be a
    major effort.

Actually, you don't even want to XCloseDisplay() in the process that
won't be using the connection; this could flush buffered data twice.
Either ignore the X connection entirely or close its file descriptor
without letting Xlib know: close(XConnectionNumber(dpy)).

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu