Dokumentation
Your isolated processes lack efficient primitives for Inter Process Communication (IPC). One such mechanism for synchronous notification is provided by send
-receive
-reply
, which has a clear hierarchy and therefore avoids deadlock situations with two threads sending each other at the same time.
System Calls for Synchronous Inter Process Communication
You have to implement the following system calls:
- sends the message invoid send(int pid, const void *sbuffer, size_t ssize, void *rbuffer, size_t rsize);
sbuffer
with the lengthssize
synchronously to the process with the PIDpid
. This operation blocks until the recipient has received the message withrecv()
, processed and sent an answer usingreply()
. This response is stored inrbuffer
, with the maximum buffer sizersize
. - blocks the current process until it receives a message. The message is stored inint recv(void *buffer, size_t size);
buffer
up to a maximum length ofsize
bytes. The return value contains the process identification (PID) of the sender. - sends a response message to the process identified byvoid reply(int pid, const void *buffer, size_t size);
pid
. This function should not block and only success if the target process has already performed a correspondingsend()
to this process and is waiting for its completion.
Test Application
You should extensively test your implementation. The fork
system call can be an important assistant for this purpose.
Nevertheless, we provide an additional test case for you – since your StuBS might have a slightly different syscall naming scheme/semantic (e.g. the first parameter of write
) you have to adapt the code accordingly:
Due to the fork()
calls, this application will split into four pairs of threads. In each pair, one thread (parent) will wait for a message while the other thread (child) sends the message. The parent thread then calculates a value from the message and sends the buffer back.
On correct implementation of the system calls above, the output of this test application should be similar to:
The lines can appear in any order. The two letters following Reply
depend on your implementation of the process identification assignment. However, on a single line those two letters must be equal (in this case good
will be appended), otherwise you have an incomplete implementation (bad!
)