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


Displaying All Message Queues on the System



tải về 6.93 Mb.
Chế độ xem pdf
trang802/806
Chuyển đổi dữ liệu08.07.2022
Kích6.93 Mb.
#52607
1   ...   798   799   800   801   802   803   804   805   806
The Linux Programming Interface

46.6
Displaying All Message Queues on the System
In Section 45.7, we looked at one way to obtain a list of all of the IPC objects on the
system: via a set of files in the 
/proc
file system. We now look at a second method of
obtaining the same information: via a set of Linux-specific IPC ctl (msgctl(), semctl(),
Table 46-1: System V message queue limits
Limit
Ceiling value (x86-32)
Corresponding file 
in 
/proc/sys/kernel
MSGMNI
32768 (IPCMNI)
msgmni
MSGMAX
Depends on available memory
msgmax
MSGMNB
2147483647 (INT_MAX)
msgmnb


952
Chapter 46
and shmctl()) operations. (The ipcs program employs these operations.) These oper-
ations are as follows:
z
MSG_INFO

SEM_INFO
, and 
SHM_INFO
: The 
MSG_INFO
operation serves two purposes. First, it
returns a structure detailing resources consumed by all message queues on the
system. Second, as the function result of the ctl call, it returns the index of the max-
imum item in the entries array pointing to data structures for the message queue
objects (see Figure 45-1, on page 932). The 
SEM_INFO
and 
SHM_INFO
operations
perform an analogous task for semaphore sets and shared memory segments,
respectively. We must define the 
_GNU_SOURCE
feature test macro to obtain the defini-
tions of these three constants from the corresponding System V IPC header files.
An example showing the use of 
MSG_INFO
to retrieve a msginfo structure contain-
ing information about resources used by all message queue objects is provided
in the file 
svmsg/svmsg_info.c
in the source code distribution for this book.
z
MSG_STAT

SEM_STAT
, and 
SHM_STAT
: Like the 
IPC_STAT
operation, these operations
retrieve the associated data structure for an IPC object. However, they differ in
two respects. First, instead of expecting an IPC identifier as the first argument
of the ctl call, these operations expect an index into the entries array. Second, if
the operation is successful, then, as its function result, the ctl call returns the
identifier of the IPC object corresponding to that index. We must define the
_GNU_SOURCE
feature test macro to obtain the definitions of these three constants
from the corresponding System V IPC header files.
To list all message queues on the system, we can do the following:
1. Use a 
MSG_INFO
operation to find out the maximum index (maxind) of the entries
array for message queues.
2. Perform a loop for all values from 0 up to and including maxind, employing a
MSG_STAT
operation for each value. During this loop, we ignore the errors that
may occur if an item of the entries array is empty (
EINVAL
) or if we don’t have
permissions on the object to which it refers (
EACCES
).
Listing 46-6 provides an implementation of the above steps for message queues.
The following shell session log demonstrates the use of this program:
./svmsg_ls
maxind: 4
index ID key messages
2 98306 0x00000000 0
4 163844 0x000004d2 2
ipcs -q
Check above against output of ipcs
------ Message Queues --------
key msqid owner perms used-bytes messages
0x00000000 98306 mtk 600 0 0
0x000004d2 163844 mtk 600 12 2


System V Message Queues

tải về 6.93 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   798   799   800   801   802   803   804   805   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