linux 消息队列使用1

来源:互联网 发布:python ..日期时间 编辑:程序博客网 时间:2024/05/23 20:41

本来以为使用多线程处理队列就可以了,但是带我的人说这样做意义不大,最好是写个进程来处理队列,这样就要用到了进程间通信,这边我们使用的是linux的消息队列。

 

使用linux消息队列有很多限制,比如每个队列中的消息数量,每个消息的大小,以及系统中的队列的个数。这边来小结下这些参数的设置。

 

msg_max:max number of messages in the queue(0-32768)
msgsize_max:max byte size of a message in the queue(0-INT_MAX)
queue_max:max number of queue in the system(0-INT_MAX)

we can change the paramters directly in the /pro/sys/fs/mqueue/.

e.g. echo "100" > /proc/sys/fs/mqueue/msg_max

 

we also can change these parameters in the /etc/sysctl.conf
Add these lines in the /etc/sysctl.conf

****************************************************
fs.mqueue.msg_max=100#max number of message in the queue
fs.mqueue.msgsize_max=8192#max size of message in the queue
fs.mqueue.queues_max = 100;#max number of queue in the system

*******************************************************

we aslo need change the default max size of memory used in the mqueue
we should add the following line in the /etc/security/limits.conf
#(user)     (type)      (item)           (value)

#**************************************************
       *           -           msgqueue         unlimited

#**************************************************

 

we can use sysctl -p to make the change in the sysctl.conf take

effect

 

we can use ulimit -q to check the value of max memory size of mqueue

in the system

 

After reboot these parameters are still available

 

If we set the attribute of the mqueue in the code which exceeds the ceiling of these parameters set in the sysctl.conf or /proc/sys/fs/mqueue,mqueue can not be created and error code will be set in the errno.

原创粉丝点击