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


Creating or Opening a Message Queue



tải về 6.93 Mb.
Chế độ xem pdf
trang792/806
Chuyển đổi dữ liệu08.07.2022
Kích6.93 Mb.
#52607
1   ...   788   789   790   791   792   793   794   795   ...   806
The Linux Programming Interface

46.1
Creating or Opening a Message Queue
The msgget() system call creates a new message queue or obtains the identifier of an
existing queue.
The key argument is a key generated using one of the methods described in Sec-
tion 45.2 (i.e., usually the value 
IPC_PRIVATE
or a key returned by ftok()). The msgflg
argument is a bit mask that specifies the permissions (Table 15-4, on page 295) to
be placed on a new message queue or checked against an existing queue. In addition,
zero or more of the following flags can be ORed (
|
) in msgflg to control the operation
of msgget():
IPC_CREAT
If no message queue with the specified key exists, create a new queue.
IPC_EXCL
If 
IPC_CREAT
was also specified, and a queue with the specified key already
exists, fail with the error 
EEXIST
.
These flags are described in more detail in Section 45.1.
The msgget() system call begins by searching the set of all existing message
queues for one with the specified key. If a matching queue is found, the identifier
of that queue is returned (unless both 
IPC_CREAT
and 
IPC_EXCL
were specified in msgflg,
in which case an error is returned). If no matching queue was found and 
IPC_CREAT
was specified in msgflg, a new queue is created and its identifier is returned.
The program in Listing 46-1 provides a command-line interface to the msgget()
system call. The program permits the use of command-line options and arguments
to specify all possibilities for the key and msgflg arguments to msgget(). Details of the
command format accepted by this program are shown in the usageError() function.
Upon successful queue creation, the program prints the queue identifier. We dem-
onstrate the use of this program in Section 46.2.2.
Listing 46-1: Using 
msgget()
––––––––––––––––––––––––––––––––––––––––––––––––––––––

tải về 6.93 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   788   789   790   791   792   793   794   795   ...   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