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



tải về 6.93 Mb.
Chế độ xem pdf
trang801/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

Listing 46-5: Changing the 
msg_qbytes
setting of a System V message queue
––––––––––––––––––––––––––––––––––––––––––––––––––––
svmsg/svmsg_chqbytes.c
#include 
#include 
#include "tlpi_hdr.h"
int
main(int argc, char *argv[])
{
struct msqid_ds ds;
int msqid;


950
Chapter 46
if (argc != 3 || strcmp(argv[1], "--help") == 0)
usageErr("%s msqid max-bytes\n", argv[0]);
/* Retrieve copy of associated data structure from kernel */
msqid = getInt(argv[1], 0, "msqid");
if (msgctl(msqid, IPC_STAT, &ds) == -1)
errExit("msgctl");
ds.msg_qbytes = getInt(argv[2], 0, "max-bytes");
/* Update associated data structure in kernel */
if (msgctl(msqid, IPC_SET, &ds) == -1)
errExit("msgctl");
exit(EXIT_SUCCESS);
}
––––––––––––––––––––––––––––––––––––––––––––––––––––
svmsg/svmsg_chqbytes.c
46.5
Message Queue Limits
Most UNIX implementations impose various limits on the operation of System V
message queues. Here, we describe the limits under Linux and note a few differ-
ences from other UNIX implementations.
The following limits are enforced on Linux. The system call affected by the
limit and the error that results if the limit is reached are noted in parentheses.
MSGMNI
This is a system-wide limit on the number of message queue identifiers (in
other words, message queues) that can be created. (msgget(), 
ENOSPC
)
MSGMAX
This is a system-wide limit specifying the maximum number of (mtext) bytes
that can be written in a single message. (msgsnd(), 
EINVAL
)
MSGMNB
This is the maximum number of (mtext) bytes that can be held in a message
queue at one time. This limit is a system-wide parameter that is used to ini-
tialize the msg_qbytes field of the msqid_ds data structure associated with this
message queue. Subsequently, the msg_qbytes value can be modified on a
per-queue basis, as described in Section 46.4. If a queue’s msg_qbytes limit is
reached, then msgsnd() blocks, or fails with the error 
EAGAIN
if 
IPC_NOWAIT
was set.
Some UNIX implementations also define the following further limits:
MSGTQL
This is a system-wide limit on the number of messages that can be placed
on all message queues on the system.
MSGPOOL
This is a system-wide limit on the size of the buffer pool that is used to hold
data in all message queues on the system.


System V Message Queues
951
Although Linux doesn’t impose either of the above limits, it does limit the number
of messages on an individual queue to the value specified by the queue’s msg_qbytes
setting. This limitation is relevant only if we are writing zero-length messages to a
queue. It has the effect that the limit on the number of zero-length messages is the
same as the limit on the number of 1-byte messages that can be written to the queue.
This is necessary to prevent an infinite number of zero-length messages being written
to the queue. Although they contain no data, each zero-length message consumes a
small amount of memory for system bookkeeping overhead.
At system startup, the message queue limits are set to default values. These
defaults have varied somewhat across kernel versions. (Some distributors’ kernels
set different defaults from those provided by vanilla kernels.) On Linux, the limits
can be viewed or changed via files in the 
/proc
file system. Table 46-1 shows the 
/proc
file corresponding to each limit. As an example, here are the default limits that we
see for Linux 2.6.31 on one x86-32 system:
cd /proc/sys/kernel
cat msgmni
748
cat msgmax
8192
cat msgmnb
16384
The ceiling value column of Table 46-1 shows the maximum value to which each
limit can be raised on the x86-32 architecture. Note that although the 
MSGMNB
limit
can be raised to the value 
INT_MAX
, some other limit (e.g., lack of memory) will be
reached before a message queue can be loaded with so much data.
The Linux-specific msgctl() 
IPC_INFO
operation retrieves a structure of type
msginfo, which contains the values of the various message queue limits:
struct msginfo buf;
msgctl(0, IPC_INFO, (struct msqid_ds *) &buf);
Details about 
IPC_INFO
and the msginfo structure can be found in the msgctl(2)
manual page.

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