سؤال

I want to know how can I configure posix queue on linux OS. I know the ways I can edit in sysctl.conf and in code by

mq_open(**,**,**);

Is there any other way I can configure the number of messages per queue and the number of queues.

هل كانت مفيدة؟

المحلول

You are mixing different layers of the onion.

  1. On the individual queue layer, the queue attributes (mq_maxmsg and mq_msgsize) are fixed at the time of the queue creation and can't be changed. mq_curmsgs doesn't make any sense to change unless you are looking to mangle your queue and can only be queried through mq_getattr. The mq_flags can be changed through mq_setattr` but the only flag to be changed is to toggle the blocking/non-blocking state of the queue.

    As practical matter it is easy to write simple command line utilities to do most of the above and many organizations will already have them. They are usually among the first programs using queues that developers write for themselves anyway. Some systems will incorporate these little utilities into startup and shutdown scripts for their applications.

  2. On the process layer, there are limits on message priorities (MQ_PRIO_MAX) and the number of queues a process can have open (MQ_OPEN_MAX). In linux neither of these are a real concern. The max priority is like 32k - sysconf(_SC_MQ_PRIO_MAX) - and if you are using that many priorities you have some real design issues. And because mqd_t types in linux are file descriptors the real limiting factors on the number of open queues is the total number of file descriptors to which a process is limited.

  3. At the system level, there are limit files in /proc/sys/fs/mqueue that can be changed with appropriate permissions. (a) queues_max is the upper limit on the number of queues allowed on a system in toto but a privileged user can still create queues once this limit has been hit. (b) msgsize_max is the max message size of a message created by an unprivileged process. (c) msg_max is the largest message size allowed for a queue. (d) Linux also has two files msg_default and msgsize_default in /proc/sys/fs/mqueue that should be self-evident.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top