Skip to main content

Posts

Showing posts from September 12, 2010

Interprocess Communication or IPC, Message Queue

Unix에서의 interporcess의 통신에는 여러가지가 있다. 그 대표적인 것으로, pipes or FIFOS, message queues semaphores shared memory sockets streams이 있다. 그 중에서 Message Queues에 대해서 알아보자 ipcs -q로, kernel에 존재하는 Message Queues를 확인할 수 있다. msgget으로 새로운 큐가 생성되거나, 존재하는 큐를 획득할 수 있다. msgsnd로 의해 발생한 새로운 메세지는 queue의 끝에 추가된다 msgrcv로 의해 메세지를 first-in, first-out order로 fetch된다. MSGMAX, 2048bytes the size of the largest message. MSGMNB, 4096bytes the maximum size of a particular queue MSGMNI, 50 the maximum number of messages queues. MSGTQL, 40 the maximum number of messages Initialising the Message Queue #include &lt sys/types.h &gt #include &lt sys/ipc.h&gt #include &lt sys/msg.h&gt int msgget(key_t key, int msgflag); msgflag는 octal integer이고 Queue's permission and control flags이다 IPC_CREAT IPC_EXCL 만 사용가능 IPC_EXCL지정후, IPC structure가 이미 존재할 경우, EEXIST에러발생 msgget 실패시, -1 성공시, nonnegative message queue ID 이 id는 다른 함수에서 사용할 수 있다. send쪽에서는 msgget(key, IPC_CR