設置調整mq_queue的size*num如果大於預設(POSIX message queues),則需要調整系統限制和用戶限制,不然在mq_open是會報"Too many open files"的錯誤 1. man mq_overview命令可以瞭解到mq可以設置msg_max和msgsize_ ...
設置調整mq_queue的size*num如果大於預設(POSIX message queues),則需要調整系統限制和用戶限制,不然在mq_open是會報"Too many open files"的錯誤
1. man mq_overview命令可以瞭解到mq可以設置msg_max和msgsize_max的路徑,預設是10與8192.這個限制是系統限制
/proc/sys/fs/mqueue/msg_max
This file can be used to view and change the ceiling value for
the maximum number of messages in a queue. This value acts as a
ceiling on the attr->mq_maxmsg argument given to mq_open(3).
The default value for msg_max is 10. The minimum value is 1 (10
in kernels before 2.6.28). The upper limit is HARD_MSGMAX. The
msg_max limit is ignored for privileged processes
(CAP_SYS_RESOURCE), but the HARD_MSGMAX ceiling is nevertheless
imposed.
The definition of HARD_MSGMAX has changed across kernel ver‐
sions:
* Up to Linux 2.6.32: 131072 / sizeof(void *)
* Linux 2.6.33 to 3.4: (32768 * sizeof(void *) / 4)
* Since Linux 3.5: 65,536
/proc/sys/fs/mqueue/msgsize_max
This file can be used to view and change the ceiling on the max‐
imum message size. This value acts as a ceiling on the
attr->mq_msgsize argument given to mq_open(3). The default
value for msgsize_max is 8192 bytes. The minimum value is 128
(8192 in kernels before 2.6.28). The upper limit for msg‐
size_max has varied across kernel versions:
* Before Linux 2.6.28, the upper limit is INT_MAX.
* From Linux 2.6.28 to 3.4, the limit is 1,048,576.
* Since Linux 3.5, the limit is 16,777,216 (HARD_MSGSIZEMAX).
The msgsize_max limit is ignored for privileged process
(CAP_SYS_RESOURCE), but, since Linux 3.5, the HARD_MSGSIZEMAX
ceiling is enforced for privileged processes.
2. ulimit -a命令可以顯示POSIX message queues (bytes, -q) 819200, ulimit -q xxx對於普通用戶無法進行調整
一般用戶調整該項設置會提示許可權問題,或者無法看到該項顯示。
這樣就需要root許可權或者sudo修改/etc/security/limits.conf, 比如調整為* - msgqueue 921600
明確在/etc/pam.d/login載入中生效, 有這項紀錄session required pam_limits.so即表明會載入,但需要重啟系統進行載入,載入成功後,一般用戶的該值就會被設置為新限制。
註:mq_name需要註意,open後必須刪掉,否則即使調整屬性也是無法生效的。