79 lines
4.3 KiB
HTML
79 lines
4.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
|
<!--Converted with LaTeX2HTML 96.1-c (Feb 29, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>IPC Keys</TITLE>
|
|
<META NAME="description" CONTENT="IPC Keys">
|
|
<META NAME="keywords" CONTENT="lpg">
|
|
<META NAME="resource-type" CONTENT="document">
|
|
<META NAME="distribution" CONTENT="global">
|
|
<LINK REL=STYLESHEET HREF="lpg.css">
|
|
</HEAD>
|
|
<BODY LANG="EN">
|
|
<A NAME="tex2html674" HREF="node25.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME="tex2html672" HREF="node22.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME="tex2html666" HREF="node23.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME="tex2html676" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME="tex2html675" HREF="node25.html">The ipcs Command</A>
|
|
<B>Up:</B> <A NAME="tex2html673" HREF="node22.html">6.4.1 Fundamental Concepts</A>
|
|
<B> Previous:</B> <A NAME="tex2html667" HREF="node23.html">IPC Identifiers</A>
|
|
<BR> <P>
|
|
<H3><A NAME="SECTION00741200000000000000">IPC Keys</A></H3>
|
|
<P>
|
|
To obtain a unique ID, a <EM>key</EM> must be used. The key must be mutually
|
|
agreed upon by both client and server processes. This represents the first
|
|
step in constructing a client/server framework for an application.
|
|
<P>
|
|
<EM>When you use a telephone to call someone, you
|
|
must know their number. In addition, the phone company must know how to relay
|
|
your outgoing call to its final destination. Once the other party responds
|
|
by answering the telephone call, the connection is made.</EM>
|
|
<P>
|
|
In the case of System V IPC facilities, the ``telephone'' correllates directly
|
|
with the type of object being used. The ``phone company'', or routing method,
|
|
can be directly associated with an IPC key.
|
|
<P>
|
|
The key can be the same value every time, by hardcoding a key value into an
|
|
application. This has the disadvantage of the key possibly being in use
|
|
already. Often, the ftok() function is used to generate key values for both
|
|
the client and the server.
|
|
<P>
|
|
<P>
|
|
<HR><PRE> LIBRARY FUNCTION: ftok();
|
|
|
|
PROTOTYPE: key_t ftok ( char *pathname, char proj );
|
|
RETURNS: new IPC key value if successful
|
|
-1 if unsuccessful, errno set to return of stat() call</PRE>
|
|
<HR>The returned key value from ftok() is generated by combining the inode number
|
|
and minor device number from the file in argument one, with the one character
|
|
project indentifier in the second argument. This doesn't guarantee uniqueness,
|
|
but an application can check for collisions and retry the key generation.
|
|
<P>
|
|
<P>
|
|
<HR><PRE> key_t mykey;
|
|
mykey = ftok("/tmp/myapp", 'a');</PRE>
|
|
<HR>In the above snippet, the directory <TT>/tmp/myapp</TT> is combined with the
|
|
one letter identifier of <TT>'a'</TT>. Another common example is to use the
|
|
current directory:
|
|
<P>
|
|
<P>
|
|
<HR><PRE> key_t mykey;
|
|
mykey = ftok(".", 'a');</PRE>
|
|
<HR>The key generation algorithm used is completely up to the discretion of the
|
|
application programmer. As long as measures are in place to prevent race
|
|
conditions, deadlocks, etc, any method is viable. For our demonstration
|
|
purposes, we will use the ftok() approach. If we assume that each client
|
|
process will be running from a unique ``home'' directory, the keys generated
|
|
should suffice for our needs.
|
|
<P>
|
|
The key value, however it is obtained, is used in subsequent IPC system calls
|
|
to create or gain access to IPC objects.
|
|
<P>
|
|
<HR><A NAME="tex2html674" HREF="node25.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME="tex2html672" HREF="node22.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME="tex2html666" HREF="node23.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME="tex2html676" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME="tex2html675" HREF="node25.html">The ipcs Command</A>
|
|
<B>Up:</B> <A NAME="tex2html673" HREF="node22.html">6.4.1 Fundamental Concepts</A>
|
|
<B> Previous:</B> <A NAME="tex2html667" HREF="node23.html">IPC Identifiers</A>
|
|
<P><ADDRESS>
|
|
<I>Converted on: <BR>
|
|
Fri Mar 29 14:43:04 EST 1996</I>
|
|
</ADDRESS>
|
|
</BODY>
|
|
</HTML>
|