aboutsummaryrefslogtreecommitdiff
path: root/aufgabe2/conv.c
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2011-01-10 20:02:33 +0100
committerThorsten Töpper <atsutane@freethoughts.de>2011-01-10 20:02:33 +0100
commit7d28c089b45d465b18df1c5cda72abed3748118f (patch)
treeef76676071fab64337bf4e5a13a4746737a2320f /aufgabe2/conv.c
parentab2f94a13428cbf1ea5f1f7acf9cf4fc33a114fb (diff)
downloadprozesskommunikation-7d28c089b45d465b18df1c5cda72abed3748118f.tar.gz
prozesskommunikation-7d28c089b45d465b18df1c5cda72abed3748118f.tar.bz2
Aufgabe 2: main.c, log.c und conv.c ausgebaut.
* main.c: Öffnen der Pipes * conv.c: Pseudozufallszahlen, schreiben in die Pipes zum log und statistic Prozess * log.c: log() implementiert
Diffstat (limited to 'aufgabe2/conv.c')
-rw-r--r--aufgabe2/conv.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/aufgabe2/conv.c b/aufgabe2/conv.c
index efa8200..a28f120 100644
--- a/aufgabe2/conv.c
+++ b/aufgabe2/conv.c
@@ -1,18 +1,47 @@
/*
* vim:ts=4:sw=4:expandtab
- *
+ *
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <limits.h>
+
+#include "queue.h"
+
+FILE *pipe_log;
+FILE *pipe_stat;
void conv() {
- printf("conv started\n");
+ int random_number = 0;
+
+ /* Die beiden Pipes zum schreiben öffnen */
+ if (((pipe_log = fdopen(queue[D_CONV_TO_LOG][WRITE], "w")) == NULL) ||
+ ((pipe_stat = fdopen(queue[D_CONV_TO_STAT][WRITE], "w")) == NULL)) {
+ perror("conv.c fdopen()");
+ exit(EXIT_FAILURE);
+ }
+
for (;;) {
+ /* Generierung der Zufallszahl, um Fehler im
+ * statistic Prozess zu vermeiden mit geringerem
+ * Wertebereich [0, SHRT_MAX] (quasi als short).
+ */
+ random_number = rand()%SHRT_MAX;
+
+ /* Nachricht sowohl in die Queue zum log Prozess als auch
+ * in die Queue zum statistic Prozess schreiben.
+ */
+ fprintf(pipe_log, "%x\n", random_number);
+ fprintf(pipe_stat, "%x\n", random_number);
}
}
void conv_cleanup() {
printf("conv cleanup\n");
+ fclose(pipe_log);
+ fclose(pipe_stat);
+ close(queue[D_CONV_TO_LOG][WRITE]);
+ close(queue[D_CONV_TO_STAT][WRITE]);
_exit(EXIT_SUCCESS);
}