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



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

svmsg/svmsg_rm.c
46.4
Message Queue Associated Data Structure
Each message queue has an associated msqid_ds data structure of the following form:
struct msqid_ds {
struct ipc_perm msg_perm; /* Ownership and permissions */
time_t msg_stime; /* Time of last msgsnd() */
time_t msg_rtime; /* Time of last msgrcv() */
time_t msg_ctime; /* Time of last change */
unsigned long __msg_cbytes; /* Number of bytes in queue */
msgqnum_t msg_qnum; /* Number of messages in queue */
msglen_t msg_qbytes; /* Maximum bytes in queue */
pid_t msg_lspid; /* PID of last msgsnd() */
pid_t msg_lrpid; /* PID of last msgrcv() */
};
The purpose of the abbreviated spelling msq in the name msqid_ds is to confuse
the programmer. This is the only message queue interface employing this spelling.
The msgqnum_t and msglen_t data types—used to type the msg_qnum and msg_qbytes
fields—are unsigned integer types specified in SUSv3.
The fields of the msqid_ds structure are implicitly updated by the various mes-
sage queue system calls, and certain fields can be explicitly updated using the
msgctl() 
IPC_SET
operation. The details are as follows:
msg_perm
When the message queue is created, the fields of this substructure are ini-
tialized as described in Section 45.3. The uid, gid, and mode subfields can be
updated via 
IPC_SET
.
msg_stime
When the queue is created, this field is set to 0; each later successful
msgsnd() sets this field to the current time. This field and the other timestamp
fields in the msqid_ds structure are typed as time_t; they store time in sec-
onds since the Epoch.
msg_rtime
This field is set to 0 when the message queue is created, and then set to the
current time on each successful msgrcv().


System V Message Queues
949
msg_ctime
This field is set to the current time when the message queue is created and
whenever an 
IPC_SET
operation is successfully performed.
__msg_cbytes
This field is set to 0 when the message queue is created, and then adjusted
during each successful msgsnd() and msgrcv() to reflect the total number of
bytes contained in the mtext fields of all messages in the queue.
msg_qnum
When the message queue is created, this field is set to 0. It is then incre-
mented by each successful msgsnd() and decremented by each successful
msgrcv() to reflect the total number of messages in the queue.
msg_qbytes
The value in this field defines an upper limit on the number of bytes in the
mtext fields of all messages in the message queue. This field is initialized to
the value of the 
MSGMNB
limit when the queue is created. A privileged
(
CAP_SYS_RESOURCE
) process can use the 
IPC_SET
operation to adjust msg_qbytes
to any value in the range 0 to 
INT_MAX
(2,147,483,647 on 32-bit platforms)
bytes. An unprivileged process can adjust msg_qbytes to any value in the
range 0 to 
MSGMNB
. A privileged user can modify the value contained in the
Linux-specific 
/proc/sys/kernel/msgmnb
file in order to change the initial
msg_qbytes setting for all subsequently created message queues, as well as
the upper limit for subsequent changes to msg_qbytes by unprivileged pro-
cesses. We say more about message queue limits in Section 46.5.
msg_lspid
This field is set to 0 when the queue is created, and then set to the process
ID of the calling process on each successful msgsnd().
msg_lrpid
This field is set to 0 when the message queue is created, and then set to the
process ID of the calling process on each successful msgrcv().
All of the above fields are specified by SUSv3, with the exception of __msg_cbytes. Never-
theless, most UNIX implementations provide an equivalent of the __msg_cbytes field.
The program in Listing 46-5 demonstrates the use of the 
IPC_STAT
and 
IPC_SET
operations to modify the msg_qbytes setting of a message queue.

tải về 6.93 Mb.

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