blob: a28f1205792422bceaf186e2c5282e5c33d6692e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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() {
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);
}
|