aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aufgabe3/log.c4
-rw-r--r--aufgabe3/monitor.c39
2 files changed, 39 insertions, 4 deletions
diff --git a/aufgabe3/log.c b/aufgabe3/log.c
index d38adfd..88a394d 100644
--- a/aufgabe3/log.c
+++ b/aufgabe3/log.c
@@ -17,7 +17,7 @@ void logmsg() {
/* Message Queue zur Kommunikation mit dem conv Prozess öffnen.
*/
- if ((log = mq_open(MQ_TO_LOG, O_RDWR)) == -1) {
+ if ((log = mq_open(MQ_TO_LOG, O_RDONLY)) == -1) {
perror("logmsg() mq_open");
exit(EXIT_FAILURE);
}
@@ -31,7 +31,7 @@ void logmsg() {
/*
* Speicher für Nachricht allokieren.
*/
- if ((message = calloc(1, MQ_MSG_SIZE_SEND)) == NULL) {
+ if ((message = calloc(1, MQ_MSG_SIZE_RCV)) == NULL) {
perror("logmsg()");
exit(EXIT_FAILURE);
}
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);
}