怎样在程序中修改一个系统V消息队列中消息的个数::

如题:想通过程序中的系统调用修改一个消息队列中消息的个数:
 例如:megctl(msqid,IPC_SET,msqid_ds*buf);
但是;书上说只能修改msqid_ds结构中的四个字段:msg _perm.uid、msg_perm_gid、msgg_perm .mode和msg_perm.qbytes.
具体怎样设置??高人出手!!!

作者: moye112   发布时间: 2011-05-23

查手册。
我经常用"www.die.net"查函数。

C/C++ code

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; /* Current number of bytes in
                                    queue (non-standard) */
    msgqnum_t      msg_qnum;     /* Current number of messages
                                    in queue */
    msglen_t       msg_qbytes;   /* Maximum number of bytes
                                    allowed in queue */
    pid_t          msg_lspid;    /* PID of last msgsnd() */
    pid_t          msg_lrpid;    /* PID of last msgrcv() */
};




IPC_SET 
Write the values of some members of the msqid_ds structure pointed to by buf to the kernel data structure associated with this message queue, updating also its msg_ctime member. The following members of the structure are updated: msg_qbytes, msg_perm.uid, msg_perm.gid, and (the least significant 9 bits of) msg_perm.mode. The effective UID of the calling process must match the owner (msg_perm.uid) or creator (msg_perm.cuid) of the message queue, or the caller must be privileged. Appropriate privilege (Linux: the CAP_IPC_RESOURCE capability) is required to raise the msg_qbytes value beyond the system parameter MSGMNB. 


确定你的消息大小,把msg_qbytes设置为“消息大小*消息个数”

作者: zhaokai3000   发布时间: 2011-05-24

貌似msgctl不能修改消息个数,只有消息队列容量

可以通过调整内核参数的方式调整消息个数
MSGSEG 在单个队列里能存在的最大数量的消息片断。

参考Linux IPC 参数设定

作者: justkk   发布时间: 2011-05-24