diff options
| author | Thorsten Töpper <atsutane@freethoughts.de> | 2011-01-03 02:39:29 +0100 |
|---|---|---|
| committer | Thorsten Töpper <atsutane@freethoughts.de> | 2011-01-03 02:39:29 +0100 |
| commit | 3bc36622e01fae96154f1d63cfa94748538d6e59 (patch) | |
| tree | 50eee91518cfe0c54fc2104a3664c642d9d5f2d2 /aufgabe3/monitor.c | |
| parent | 89f32cb9767074cd9ab01d8bcc4b164a4f3ac83d (diff) | |
| download | prozesskommunikation-3bc36622e01fae96154f1d63cfa94748538d6e59.tar.gz prozesskommunikation-3bc36622e01fae96154f1d63cfa94748538d6e59.tar.bz2 | |
Aufgabe 3: monitor implementiert, log.c korrigiert.
Diffstat (limited to 'aufgabe3/monitor.c')
| -rw-r--r-- | aufgabe3/monitor.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/aufgabe3/monitor.c b/aufgabe3/monitor.c index b631e59..02eee15 100644 --- a/aufgabe3/monitor.c +++ b/aufgabe3/monitor.c @@ -1,18 +1,53 @@ /* * vim:ts=4:sw=4:expandtab - * + * */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> +#include "queue.h" + +char *message; + void monitor() { - printf("monitor started\n"); + int random_number = 0; + mqd_t monitor; + + /* + * Message Queue zur Kommunikation mit dem statistic Prozess öffnen. + */ + if ((monitor = mq_open(MQ_TO_MONITOR, O_RDONLY)) == -1) { + perror("monitor() mq_open"); + exit(EXIT_FAILURE); + } + + /* + * Speicher für Nachricht allokieren. + */ + if ((message = calloc(1, MQ_MSG_SIZE_RCV)) == NULL) { + perror("monitor()"); + exit(EXIT_FAILURE); + } + for (;;) { + /* Nachricht über monitor Queue vom statistic Prozess empfangen */ + if (mq_receive(monitor, message, MQ_MSG_SIZE_RCV, NULL) == -1) { + perror("monitor() mq_receive"); + exit(EXIT_FAILURE); + } + + /* Zufallszahl aus dem String zurück zur Dezimalzahl konvertieren */ + sscanf(message, "%x", &random_number); + + /* Die konvertierte Zahl auf der stdout ausgeben */ + printf("%d\n", random_number); } } void monitor_cleanup() { printf("monitor cleanup\n"); + free(message); + mq_unlink(MQ_TO_MONITOR); _exit(EXIT_SUCCESS); } |
