aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aufgabe4/Makefile10
-rw-r--r--aufgabe4/README1
-rw-r--r--aufgabe4/conv.c18
-rw-r--r--aufgabe4/conv.h7
-rw-r--r--aufgabe4/log.c18
-rw-r--r--aufgabe4/log.h7
-rw-r--r--aufgabe4/main.c86
-rw-r--r--aufgabe4/monitor.c18
-rw-r--r--aufgabe4/monitor.h7
-rw-r--r--aufgabe4/statistic.c18
-rw-r--r--aufgabe4/statistic.h7
11 files changed, 197 insertions, 0 deletions
diff --git a/aufgabe4/Makefile b/aufgabe4/Makefile
new file mode 100644
index 0000000..d08af51
--- /dev/null
+++ b/aufgabe4/Makefile
@@ -0,0 +1,10 @@
+all:
+ gcc -Wall -c -o conv.o conv.c
+ gcc -Wall -c -o log.o log.c
+ gcc -Wall -c -o statistic.o statistic.c
+ gcc -Wall -c -o monitor.o monitor.c
+ gcc -Wall -c -o main.o main.c
+ gcc -o pk main.o conv.o log.o statistic.o monitor.o
+
+clean:
+ rm -f *.o
diff --git a/aufgabe4/README b/aufgabe4/README
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/aufgabe4/README
@@ -0,0 +1 @@
+foo
diff --git a/aufgabe4/conv.c b/aufgabe4/conv.c
new file mode 100644
index 0000000..efa8200
--- /dev/null
+++ b/aufgabe4/conv.c
@@ -0,0 +1,18 @@
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void conv() {
+ printf("conv started\n");
+ for (;;) {
+ }
+}
+
+void conv_cleanup() {
+ printf("conv cleanup\n");
+ _exit(EXIT_SUCCESS);
+}
diff --git a/aufgabe4/conv.h b/aufgabe4/conv.h
new file mode 100644
index 0000000..f593aab
--- /dev/null
+++ b/aufgabe4/conv.h
@@ -0,0 +1,7 @@
+#ifndef _CONV_H
+#define _CONV_H
+
+void conv();
+void conv_cleanup();
+
+#endif
diff --git a/aufgabe4/log.c b/aufgabe4/log.c
new file mode 100644
index 0000000..405cdbd
--- /dev/null
+++ b/aufgabe4/log.c
@@ -0,0 +1,18 @@
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void log() {
+ printf("log started\n");
+ for (;;) {
+ }
+}
+
+void log_cleanup() {
+ printf("log cleanup\n");
+ _exit(EXIT_SUCCESS);
+}
diff --git a/aufgabe4/log.h b/aufgabe4/log.h
new file mode 100644
index 0000000..e6b171f
--- /dev/null
+++ b/aufgabe4/log.h
@@ -0,0 +1,7 @@
+#ifndef _LOG_H
+#define _LOG_H
+
+void log();
+void log_cleanup();
+
+#endif
diff --git a/aufgabe4/main.c b/aufgabe4/main.c
new file mode 100644
index 0000000..f876f54
--- /dev/null
+++ b/aufgabe4/main.c
@@ -0,0 +1,86 @@
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "conv.h"
+#include "log.h"
+#include "monitor.h"
+#include "statistic.h"
+
+typedef void (*funcptr)();
+
+pid_t pconv;
+pid_t plog;
+pid_t pstatistic;
+pid_t pmonitor;
+
+/*
+ * Signalhandler für SIGTERM. Sendet SIGINT an die 4 Prozesse.
+ *
+ */
+void sigterm() {
+ kill(pconv, SIGINT);
+ kill(plog, SIGINT);
+ kill(pstatistic, SIGINT);
+ kill(pmonitor, SIGINT);
+}
+
+/*
+ * fork()t einen neuen Prozess. In diesem Prozess wird die übergebene Funktion
+ * work() aufgerufen, außerdem wird der Signalhandler cleanup() installiert für
+ * das Signal SIGINT.
+ *
+ */
+pid_t fork_child(funcptr work, funcptr cleanup) {
+ pid_t pid = fork();
+ if (pid == 0) {
+ /* child process */
+ signal(SIGINT, cleanup);
+
+ work();
+
+ /* Die Prozesse laufen endlos. Daher beenden wir mit Fehlercode, sofern
+ * die Prozessfunktion doch zurückkehrt. */
+ exit(EXIT_FAILURE);
+ }
+
+ if (pid == -1) {
+ /* error */
+ perror("fork()");
+ exit(EXIT_FAILURE);
+ }
+
+ /* parent process */
+ printf("forked\n");
+ return pid;
+}
+
+/*
+ * main-Funktion. Startet die 4 Prozesse, registriert einen signal-handler für
+ * SIGTERM (dieser sendet SIGINT an die 4 Prozesse) und wartet schließlich auf
+ * das Ende der Prozesse.
+ *
+ */
+int main() {
+ pconv = fork_child(conv, conv_cleanup);
+ plog = fork_child(log, log_cleanup);
+ pstatistic = fork_child(statistic, statistic_cleanup);
+ pmonitor = fork_child(monitor, monitor_cleanup);
+
+ signal(SIGTERM, sigterm);
+
+ int status;
+ waitpid(pconv, &status, 0);
+ waitpid(plog, &status, 0);
+ waitpid(pstatistic, &status, 0);
+ waitpid(pmonitor, &status, 0);
+
+ return 0;
+}
diff --git a/aufgabe4/monitor.c b/aufgabe4/monitor.c
new file mode 100644
index 0000000..b631e59
--- /dev/null
+++ b/aufgabe4/monitor.c
@@ -0,0 +1,18 @@
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void monitor() {
+ printf("monitor started\n");
+ for (;;) {
+ }
+}
+
+void monitor_cleanup() {
+ printf("monitor cleanup\n");
+ _exit(EXIT_SUCCESS);
+}
diff --git a/aufgabe4/monitor.h b/aufgabe4/monitor.h
new file mode 100644
index 0000000..c70b426
--- /dev/null
+++ b/aufgabe4/monitor.h
@@ -0,0 +1,7 @@
+#ifndef _MONITOR_H
+#define _MONITOR_H
+
+void monitor();
+void monitor_cleanup();
+
+#endif
diff --git a/aufgabe4/statistic.c b/aufgabe4/statistic.c
new file mode 100644
index 0000000..b83776a
--- /dev/null
+++ b/aufgabe4/statistic.c
@@ -0,0 +1,18 @@
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void statistic() {
+ printf("statistic started\n");
+ for (;;) {
+ }
+}
+
+void statistic_cleanup() {
+ printf("statistic cleanup\n");
+ _exit(EXIT_SUCCESS);
+}
diff --git a/aufgabe4/statistic.h b/aufgabe4/statistic.h
new file mode 100644
index 0000000..50b82f4
--- /dev/null
+++ b/aufgabe4/statistic.h
@@ -0,0 +1,7 @@
+#ifndef _STATISTIC_H
+#define _STATISTIC_H
+
+void statistic();
+void statistic_cleanup();
+
+#endif