我正在使用一個python模塊來包裝posix實時擴展以獲取MessageQueues。無法創建超過10個mqueue
這是報告OSError: This process already has the maximum number of files open
我看着MQ限制和RLIMIT並檢查它們都設定非常高的前Python代碼
#!/usr/bin env python
import uuid
import posix_ipc
import time
def spawn():
return posix_ipc.MessageQueue("/%s" % uuid.uuid4(), flags=posix_ipc.O_CREAT)
i = 0
while True:
i += 1
spawn()
print(i)
這將創造約10 MQS。例如。
fs.file-max = 2097152
fs.mqueue.msg_max = 1000
fs.mqueue.queues_max = 1000
甚至對於特權用戶,它仍然只能創建大約10個隊列。
直接使用實時擴展的等效C是如下
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <mqueue.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
int main(int argc, char **argv)
{
mqd_t mq;
struct mq_attr attr;
char buffer[1024 + 1];
int must_stop = 0;
/* initialize the queue attributes */
attr.mq_flags = 0;
attr.mq_maxmsg = 10;
attr.mq_msgsize = 1024;
attr.mq_curmsgs = 0;
/* create the message queue */
int count = 0;
char name[5];
while (1) {
sprintf(name, "/%d", count);
mq = mq_open(name, O_CREAT | O_RDONLY, 0644, &attr);
if (mq == (mqd_t) -1)
handle_error("mq_open");
count++;
}
return 0;
}
(編譯gcc -lrt test.c
) 但這只是讓我20個MQS開放一次。實際上,我希望一次有幾百或者幾千個空位。
任何人有任何想法或建議?
編輯:更好的錯誤檢查在C版本。仍然最大。
C程序錯誤檢查是不正確 - 檢查_errno_如果'mq_open'回報'(mqd_t)-1' 。 – pilcrow
@pilcrow固定它 –