diff options
| author | Michael Stapelberg <michael@stapelberg.de> | 2010-12-06 19:55:19 +0100 |
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2010-12-06 19:55:19 +0100 |
| commit | 0c9d712a77bbede4808142944776d35f502bffa7 (patch) | |
| tree | 1955e375d404308aa1d79b9d355e37dba739b9bf /aufgabe4/conv.c | |
| parent | 9af2bea582c083653c08abb965eba6f63de997fa (diff) | |
| download | prozesskommunikation-0c9d712a77bbede4808142944776d35f502bffa7.tar.gz prozesskommunikation-0c9d712a77bbede4808142944776d35f502bffa7.tar.bz2 | |
IPC implementiert
Hat noch einen Bug, sollte aber als Beispiel für die anderen Aufgaben gut genug
sein.
Diffstat (limited to 'aufgabe4/conv.c')
| -rw-r--r-- | aufgabe4/conv.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/aufgabe4/conv.c b/aufgabe4/conv.c index efa8200..919965c 100644 --- a/aufgabe4/conv.c +++ b/aufgabe4/conv.c @@ -1,18 +1,44 @@ /* * vim:ts=4:sw=4:expandtab + * + * © 2010 Michael Stapelberg * */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> +#include "queue.h" + +/* + * Conv-Prozess. Generiert Zufallszahlen und schickt sie an den Log-Prozess + * sowie an den Statistik-Prozess. + * + */ void conv() { - printf("conv started\n"); + int number; + struct msg *first; + struct msg *second; for (;;) { + /* Zufallszahl generieren */ + number = rand(); + + /* Zahl zweimal in die Queue schreiben: Einmal zum loggen, einmal für + * den Statistik-Prozess */ + first = queue_write(D_CONV_TO_LOG, number); + second = queue_write(D_CONV_TO_STAT, number); + + /* Warten, bis die Zufallszahl aus der Queue geholt wurde */ + while (first->dir == D_CONV_TO_LOG || + second->dir == D_CONV_TO_STAT) + usleep(1); } } +/* + * Cleanup-Funktion. Beendet den Prozess. + * + */ void conv_cleanup() { - printf("conv cleanup\n"); _exit(EXIT_SUCCESS); } |
