The Linux Programming Interface: a linux and unix system Programming Handbook


IPC Identifiers and Client-Server Applications



tải về 6.93 Mb.
Chế độ xem pdf
trang784/806
Chuyển đổi dữ liệu08.07.2022
Kích6.93 Mb.
#52607
1   ...   780   781   782   783   784   785   786   787   ...   806
The Linux Programming Interface

45.4
IPC Identifiers and Client-Server Applications
In client-server applications, the server typically creates the System V IPC objects,
while the client simply accesses them. In other words, the server performs an IPC
get call specifying the flag 
IPC_CREAT
, while the client omits this flag in its get call.


930
Chapter 45
Suppose a client engages in an extended dialogue with a server, with multiple
IPC operations being performed by each process (e.g., multiple messages
exchanged, a sequence of semaphore operations, or multiple updates to shared
memory). What happens if the server process crashes or is deliberately halted and
then restarted? At this point, it would make no sense to blindly reuse the existing
IPC object created by the previous server process, since the new server process has
no knowledge of the historical information associated with the current state of the
IPC object. (For example, there may be a secondary request within a message
queue that was sent by a client in response to an earlier message from the old
server process.)
In such a scenario, the only option for the server may be to abandon all existing
clients, delete the IPC objects created by the previous server process, and create new
instances of the IPC objects. A newly started server handles the possibility that a pre-
vious instance of the server terminated prematurely by first trying to create an IPC
object by specifying both the 
IPC_CREAT
and the 
IPC_EXCL
flags within the get call. If
the get call fails because an object with the specified key already exists, then the
server assumes the object was created by an old server process; it therefore uses the
IPC_RMID
ctl operation to delete the object, and once more performs a get call to create
the object. (This may be combined with other steps to ensure that another server
process is not currently running, such as those described in Section 55.6.) For a
message queue, these steps might appear as shown in Listing 45-1.

tải về 6.93 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   780   781   782   783   784   785   786   787   ...   806




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương