POSIX IPC (Slides)

History: Two IPC Variants

Object Names

File Semantics

Message Queues

man -s 7 mq_overview

Open/Create: mq_open()

mqd_t mq_open(const char *name, int oflag);
mqd_t mq_open(const char *name, int oflag, mode_t mode, struct mq_attr *attr);

man -s 3 mq_open

Sending/Receiving: mq_send(), mq_receive()

int mq_send(mqd_t mqdes, const char *msg_ptr,
            size_t msg_len, unsigned msg_prio);
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr,
            size_t msg_len, unsigned *msg_prio);

man -s 3 mq_receive

man -s 3 mq_send

Notification: mq_notify()

int mq_notify(mqd_t mqdes, const struct sigevent *sevp);

Obscure feature ...

man -s 3 mq_notify

Message Queues are Files

Notifications can be received more elegantly - select(), poll(), epoll!

Message Queue Filesystem: mqueue

# mount -t mqueue blah /mnt/mqueue
# ls -l /mnt/mqueue/my-queue
-rw------- ... /mnt/mqueue/my-queue
# cat /mnt/mqueue/my-queue
QSIZE:0          NOTIFY:0     SIGNO:0     NOTIFY_PID:0


Communication and synchronization device

Creation parameter

man -s 7 sem_overview

Open/Create: sem_open()

sem_t *sem_open(const char *name, int oflag);
sem_t *sem_open(const char *name, int oflag,
                mode_t mode, unsigned int value);

man -s 3 sem_open

Communication: sem_wait(), sem_post()

int sem_wait(sem_t *sem);
int sem_trywait(sem_t *sem);
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
int sem_post(sem_t *sem);

man -s 3 sem_wait

man -s 3 sem_post

Semaphores are Files

$ ls -l /dev/shm/
total 1604
-rw------- ... sem.my-semaphore

Shared Memory (1)

int shm_open(const char *name, int oflag, mode_t mode);
int shm_unlink(const char *name);

POSIX shared memory is almost non-existing ...

man -s 7 shm_overview

Shared Memory (2)


As simple as it can get!

Exercise: POSIX Message Queues

Add a POSIX message queue to our server like follows