diff options
author | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-05-24 12:09:46 +0200 |
---|---|---|
committer | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-05-24 12:09:46 +0200 |
commit | 65966ded0cc15c5966c6568cf0ff2f2bbe1fc29a (patch) | |
tree | 60af69be16926ef0f24ad2a954d9205ce9277450 /02_exercise/beispiele/fork_signal | |
parent | 3b7e61eab8ce5d230bc1b172942c1ab9459ed161 (diff) | |
download | betriebssysteme-65966ded0cc15c5966c6568cf0ff2f2bbe1fc29a.tar.gz betriebssysteme-65966ded0cc15c5966c6568cf0ff2f2bbe1fc29a.zip |
Big remodelling
Diffstat (limited to '02_exercise/beispiele/fork_signal')
-rw-r--r-- | 02_exercise/beispiele/fork_signal/Makefile | 19 | ||||
-rw-r--r-- | 02_exercise/beispiele/fork_signal/fork.c | 39 | ||||
-rw-r--r-- | 02_exercise/beispiele/fork_signal/signal.c | 21 |
3 files changed, 0 insertions, 79 deletions
diff --git a/02_exercise/beispiele/fork_signal/Makefile b/02_exercise/beispiele/fork_signal/Makefile deleted file mode 100644 index 499b8cb..0000000 --- a/02_exercise/beispiele/fork_signal/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/make -.SUFFIXES: - -CFLAGS = -c -O0 - -%.o: %.c - $(CC) $(CFLAGS) $^ -o $@ - -%: %.o - $(CC) -o $@ $^ - -all: fork signal - -run: all - ./fork 10 - ./signal - -clean: - $(RM) $(RMFILES) fork signal diff --git a/02_exercise/beispiele/fork_signal/fork.c b/02_exercise/beispiele/fork_signal/fork.c deleted file mode 100644 index b144577..0000000 --- a/02_exercise/beispiele/fork_signal/fork.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/wait.h> - -int main(int argc, const char* argv[]) { - pid_t pid; - int h; - int count; - - if (argc < 2) { - printf("Usage: ./fork process#\n"); - return 0; - } - - count = atoi(argv[1]) - 1; - printf("Process#: %d\n", count + 1); - printf("Parent started\n"); - - pid = 1; - for (h = 0; h < count; ++h) { - if ((pid = fork()) < 0) - printf("fork error\n"); - else if (pid == 0) { - printf("Child %d started\n", h); - sleep(1); - printf("Child %d finished\n", h); - exit(0); - } - } - - printf("Parent waiting\n"); - for (h = 0; h < count; ++h) { - wait(NULL); - } - printf("Parent finished\n"); - return EXIT_SUCCESS; -} diff --git a/02_exercise/beispiele/fork_signal/signal.c b/02_exercise/beispiele/fork_signal/signal.c deleted file mode 100644 index 500d2e1..0000000 --- a/02_exercise/beispiele/fork_signal/signal.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <signal.h> - -void sig_handler(int signo) { - const char msg[] = "Speicherzugriffsfehler!\n"; - write(2, msg, sizeof(msg) - 1); - exit(-1); -} - -int main(void) { - if (signal(SIGSEGV, sig_handler) == SIG_ERR) { - perror("signal"); - exit(-1); - } - - int array[1] = {0}; - array[1000000] = 3; - return 0; -} |