From 6762515c8e5861aa80675fe6f27be54689651e76 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 6 Dec 2010 14:47:33 +0100 Subject: Grundgerüst in eigenen Ordner verschoben MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 86 ------------------------------------------------------------------ 1 file changed, 86 deletions(-) delete mode 100644 main.c (limited to 'main.c') diff --git a/main.c b/main.c deleted file mode 100644 index f876f54..0000000 --- a/main.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * vim:ts=4:sw=4:expandtab - * - */ -#include -#include -#include -#include -#include -#include - -#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; -} -- cgit v1.2.3-70-g09d2