问题
I am toying a bit with POSIX queues and I encountered a problem. When creating a new queue I can specify for example the size of the message and how many messages there can be in the queue. My normal limit is 10 as found in
/proc/sys/fs/mqueue/msg_max
is there an easy way to change it during program execution, apart from
echo number > /proc/sys/fs/mqueue/msg_max
maybe some system call for setting such things exists.
回答1:
No.
That limit is a system-wide limit; that's why it's in /proc/sys
. If you want to change it you will have to use the echo
command you have already shown.
回答2:
The queue is set when it is created and you can't change it midstream. You can increase the number of queue messages by running as a privileged user at the time you create the queue. So you either have to run a separate program (as a PU) to create the queue or run as a PU, create the queue, and drop the privileges when done. The number of messages you can increase up to is still limited by the overall size of the queue so you have to do some division (minus a small amount of overhead byes). If you Google around there is a simple formula for this.
回答3:
Finally found this: Re: POSIX Message Queues
Edit /etc/sysctl.conf and add the lines:
# Increase message queue
fs.mqueue.msg_max = 100
Works for me on Raspbian
来源:https://stackoverflow.com/questions/10558721/posix-queues-and-msg-max