Aktualnie używam kolejek komunikatów systemu V w systemie Mac OSX i mam problemy z ustawieniem rozmiaru kolejki na wartość większą niż 2048 bajtów. Oto kompilacji stanie przykład test.c
:Ustawianie rozmiaru kolejki komunikatów systemu V w systemie Mac OSX
#include <stdio.h>
#include <sys/msg.h>
#include <stdlib.h>
int main() {
// get a message queue id
int id = msgget(IPC_PRIVATE,IPC_CREAT|0600);
if (-1 == id)
exit(1);
// get message queue data structure
struct msqid_ds buf;
if (-1 == msgctl(id, IPC_STAT, &buf))
exit(1);
printf("size is %lu bytes\n", buf.msg_qbytes);
// set new buffer size
buf.msg_qbytes = 2750;
printf("setting size to %lu bytes\n", buf.msg_qbytes);
if (-1 == msgctl(id, IPC_SET, &buf))
exit(1);
// check updated message queue data structure
if (-1 == msgctl(id, IPC_STAT, &buf))
exit(1);
printf("size is %lu bytes\n", buf.msg_qbytes);
}
skompilować z:
clang -Wall -pedantic -o test test.c
i biegać z:
sudo ./test
Uwaga: Musisz uruchomić powyższy kod z sudo
aby upewnić się, że wywołania msgcntl
zakończą się pomyślnie.
Wyjście tego programu fragmencie brzmi:
size is 2048 bytes
setting size to 2750 bytes
size is 2048 bytes
Dlaczego nie wielkość kolejka zaczyna się zmieniło?
EDIT: Wyjście ipcs -Q
Wystawy:
IPC status from <running system> as of Tue Dec 1 10:06:39 PST 2015
msginfo:
msgmax: 16384 (max characters in a message)
msgmni: 40 (# of message queues)
msgmnb: 2048 (max characters in a message queue)
msgtql: 40 (max # of messages in system)
msgssz: 8 (size of a message segment)
msgseg: 2048 (# of message segments in system)
Czy msgmnb
być wykonane większe, albo ja zatrzymany?
Spróbuj uruchomić 'ipcs-Q', aby sprawdzić, czy istnieje maksymalny rozmiar. –
@MarkSetchell - zaktualizowałem pytanie o wynik działania 'ipcs-Q'. – dinkelk
Nigdy nie próbowałem tego na OSX, i nie wiem, czy to działa lub może powodować problemy, ale myślę, że zrobiłbyś coś takiego jak 'sysctl -w kernel.msgmnb = 2000000' –