aboutsummaryrefslogtreecommitdiff
path: root/aufgabe3/monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'aufgabe3/monitor.c')
-rw-r--r--aufgabe3/monitor.c39
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);
}