Académique Documents
Professionnel Documents
Culture Documents
4 System V IPC
IPC Identifiers
Each IPC object has a unique IPC identifier associated with it. When
we say ``IPC object'', we are speaking of a single message queue,
semaphore set, or shared memory segment. This identifier is used
within the kernel to uniquely identify an IPC object. For example, to
access a particular shared memory segment, the only item you need is
the unique ID value which has been assigned to that segment.
To obtain a unique ID, a key 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.
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.
例如想要選定哪一種通訊方式:電話網路、 Internet、衛星通訊。分別就是代表著:
Message Queue/ Semaphores/ Share memory segment
key_t mykey;
mykey = ftok("/tmp/myapp", 'a');
In the above snippet, the directory /tmp/myapp is combined with the
one letter identifier of 'a'. Another common example is to use the
current directory:
key_t mykey;
mykey = ftok(".", 'a');
The ipcs command can be used to obtain the status of all System V IPC
objects. The Linux version of this tool was also authored by Krishna
Balasubramanian.
The ipcs command is a very powerful tool which provides a peek into
the kernel's storage mechanisms for IPC objects. Learn it, use it,
revere it.
The ipcrm command can be used to remove an IPC object from the
kernel. While IPC objects can be removed via system calls in user
code (we'll see how in a moment), the need often arises, especially
under development environments, to remove IPC objects manually. Its
usage is simple: