Set linux mq_queue size for user

2018-06-17 21:45:16来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

设置调整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后必须删掉,否则即使调整属性也是无法生效的。

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:UOJ #262. 【NOIP2016】换教室

下一篇:Find all factorial numbers less than or equal to N