RPC and fork()

Dan Peters peters at mips2.cr.bull.com
Tue Aug 7 07:40:16 AEST 1990


In article <46413 at brunix.UUCP> jhc at iris.brown.edu (Jim Coombs) writes:
>I normally have servers fork after accepting connections.  I am trying
>to use RPC, but I don't see anything in the documentation about
>forking.  I also don't see any good hooks in the API.
>
>Thanks for any suggestions.  --Jim

I have used NFS's RPC (Sun Microsystems) to provide an application with
remote access to library functions resident on another machine.  The user
application is linked with my RPC client code on the local machine while I
link the library into my RPC server code on the remote machine.
	The RPC 'library' server must be started up first on the remote
machine then the 'application' may be executed on the local machine.

   Upon the first library call that the local application makes, my RPC
client code (linked with the local application in place of the library) 
performs all of the RPC set-up (client create, etc.) AND makes a first-time
RPC call over the newly established client transport to tell the server
to fork.  After the success of this INITIAL remote procedure call, the
RPC client/server set-up overhead is complete.  Now RPC is used to
transparently access the remote library for the application's first library
call.  Subsequent library calls by the application also result in RPC to the
server but without the initial first-time overhead.
	All this set-up is done transparent to the local application during
what it thinks is only the first library call.

	RPC servers use 2 sockets:

	ONE to originally created by 'svctcp_create' to receive client
connection requests over and when such a connection is received by the server,
the socket 'accept' call actually creates ANOTHER socket over which all
subsequent communication (procedure calls) takes place.

	After the fork:

	The Parent server process must close the 'accept' created socket,
keeping open only the original 'svctcp_create' created socket over which it
received the client connect request.
(The Parent in this role is a daemon process that stays active only to accept
client connections and forks a child server to service the client and nothing
else.)

	The Child server process must close the 'svctcp_create' created
socket keeping open only the 'accept' created socket over which it will
receive all subsequent remote procedure calls.
(The Child in this role is the functional RPC server handling all procedure
calls from the application client EXCEPT the INITIAL remote procedure call
to fork the server.)
	This Child server process will exit when it's 'accepted' socket
connection is closed by the client application on the local machine.
	The socket will be closed by the client application on the local
machine as a result of it normal exit.

	I hope my experience is helpful to you,

Dan Peters
-- 

== Dan Peters		 	Bull HN Information Systems Inc.
== (508) 294-3325 (294-3020)	300 Concord Road 	MS 826a
== peters at mips2.cr.bull.com	Billerica, MA		01821



More information about the Comp.unix.wizards mailing list