diff options
Diffstat (limited to 'aufgabe2')
| -rw-r--r-- | aufgabe2/Makefile | 10 | ||||
| -rw-r--r-- | aufgabe2/conv.c | 18 | ||||
| -rw-r--r-- | aufgabe2/conv.h | 7 | ||||
| -rw-r--r-- | aufgabe2/log.c | 18 | ||||
| -rw-r--r-- | aufgabe2/log.h | 7 | ||||
| -rw-r--r-- | aufgabe2/main.c | 86 | ||||
| -rw-r--r-- | aufgabe2/monitor.c | 18 | ||||
| -rw-r--r-- | aufgabe2/monitor.h | 7 | ||||
| -rw-r--r-- | aufgabe2/statistic.c | 18 | ||||
| -rw-r--r-- | aufgabe2/statistic.h | 7 |
10 files changed, 196 insertions, 0 deletions
diff --git a/aufgabe2/Makefile b/aufgabe2/Makefile new file mode 100644 index 0000000..d08af51 --- /dev/null +++ b/aufgabe2/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/aufgabe2/conv.c b/aufgabe2/conv.c new file mode 100644 index 0000000..efa8200 --- /dev/null +++ b/aufgabe2/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/aufgabe2/conv.h b/aufgabe2/conv.h new file mode 100644 index 0000000..f593aab --- /dev/null +++ b/aufgabe2/conv.h @@ -0,0 +1,7 @@ +#ifndef _CONV_H +#define _CONV_H + +void conv(); +void conv_cleanup(); + +#endif diff --git a/aufgabe2/log.c b/aufgabe2/log.c new file mode 100644 index 0000000..405cdbd --- /dev/null +++ b/aufgabe2/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/aufgabe2/log.h b/aufgabe2/log.h new file mode 100644 index 0000000..e6b171f --- /dev/null +++ b/aufgabe2/log.h @@ -0,0 +1,7 @@ +#ifndef _LOG_H +#define _LOG_H + +void log(); +void log_cleanup(); + +#endif diff --git a/aufgabe2/main.c b/aufgabe2/main.c new file mode 100644 index 0000000..f876f54 --- /dev/null +++ b/aufgabe2/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/aufgabe2/monitor.c b/aufgabe2/monitor.c new file mode 100644 index 0000000..b631e59 --- /dev/null +++ b/aufgabe2/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/aufgabe2/monitor.h b/aufgabe2/monitor.h new file mode 100644 index 0000000..c70b426 --- /dev/null +++ b/aufgabe2/monitor.h @@ -0,0 +1,7 @@ +#ifndef _MONITOR_H +#define _MONITOR_H + +void monitor(); +void monitor_cleanup(); + +#endif diff --git a/aufgabe2/statistic.c b/aufgabe2/statistic.c new file mode 100644 index 0000000..b83776a --- /dev/null +++ b/aufgabe2/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/aufgabe2/statistic.h b/aufgabe2/statistic.h new file mode 100644 index 0000000..50b82f4 --- /dev/null +++ b/aufgabe2/statistic.h @@ -0,0 +1,7 @@ +#ifndef _STATISTIC_H +#define _STATISTIC_H + +void statistic(); +void statistic_cleanup(); + +#endif |
