Linux System Programming Part 6 - IPC (Synchronization) : IBA Bulgaria 2018
Linux System Programming Part 6 - IPC (Synchronization) : IBA Bulgaria 2018
Linux System Programming Part 6 - IPC (Synchronization) : IBA Bulgaria 2018
IBA Bulgaria
2018
Message queue
● Message queues can be described as an
internal linked list within the kernel's
addressing space.
● Messages can be sent to the queue in order
and retrieved from the queue in several
different ways.
● Each message queue (of course) is uniquely
identified by an IPC identifier.
Messaging in C
The msgget() system call returns the System V message queue identifier associated with the value of
the key argument.
The msgsnd() and msgrcv() system calls are used, respectively, to send messages to, and receive
messages from, a System V message queue. The calling process must have write permission on
the message queue in order to send a message, and read permission to receive a message.
msgctl() and cmd = IPC_RMID removes a message queue.
msgtypes.h
Message Server
Create a message queue with a given KEY
Message Client
Open a message queue with a given KEY
and notify and exit if failed
Memory Server
Create token ‘./shmemserv’, exit on error
Memory Client
Create token ‘./shmemserv’, exit on error
Semaphore Server
Set 2 semaphores - first indicating that the
server has to read, second for the client
Semaphore Client
Set 2 semaphores - first indicating that the
server has to read, second for the client
Write a server/client pair of programs (‘dblmemsrv.c’ and ‘dblmemcli.c’), which share blocks of memory between them.
The server supports up to 2 client instances in parallel execution, which should not interfere with each other. The server
initializes the shared memory with welcoming messages for the clients and waits for them to modify the memory with
their messages. When a new message from the client is written, the server answers with the same message, but with
‘Confirmed!” at the end.
The client is started with a single argument: client_number, which identifies the client (1 or 2) for the server. The client
should continuously print the message from the shared memory, read a line from the keyboard and write it to the shared
memory. The program should quit when ‘q’ message is entered.
Program DoubleDumper:
Write a program (‘dbldump.c’), which in real time shows the changes in the shared memory from the
DoubleSharedMemory project. You may need to modify the server and/or client programs to support this functionality.