From fb2a39bd1ea2de8c1d21b55c0961e69749b4ee8c Mon Sep 17 00:00:00 2001 From: iliya <iliya.saroukha@hes-so.ch> Date: Wed, 27 Sep 2023 19:31:53 +0200 Subject: [PATCH] vsy jsp fml --- serie1/ex6/.gitignore | 2 ++ serie1/ex6/Makefile | 23 +++++++++++++++++++++++ serie1/ex6/child_list.c | 23 +++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 serie1/ex6/.gitignore create mode 100644 serie1/ex6/Makefile create mode 100644 serie1/ex6/child_list.c diff --git a/serie1/ex6/.gitignore b/serie1/ex6/.gitignore new file mode 100644 index 0000000..37a89e9 --- /dev/null +++ b/serie1/ex6/.gitignore @@ -0,0 +1,2 @@ +*.o +child_list diff --git a/serie1/ex6/Makefile b/serie1/ex6/Makefile new file mode 100644 index 0000000..5a28c6c --- /dev/null +++ b/serie1/ex6/Makefile @@ -0,0 +1,23 @@ +CC := clang +CFLAGS := -g -pedantic -Wall -Wextra -std=c2x +LDFLAGS := -fsanitize=address -fsanitize=leak -fsanitize=undefined -lm +TARGET := child_list + +all: $(TARGET) + +$(TARGET): child_list.o + @printf "=================== Building executable ===================\n" + $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) + @printf "\n" + +%.o: %.c + @printf "================== Building object files ==================\n" + $(CC) $(CFLAGS) -c $< + @printf "\n" + +.PHONY: clean + +clean: + rm -f *.o $(TARGET) + + diff --git a/serie1/ex6/child_list.c b/serie1/ex6/child_list.c new file mode 100644 index 0000000..374753f --- /dev/null +++ b/serie1/ex6/child_list.c @@ -0,0 +1,23 @@ +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> +#define NB_PROCESSES 10 + +int main(void) { + pid_t pid = -1; + pid = fork(); + if (pid > 0) { + for (int i = 0; i < NB_PROCESSES; i++) { + fork(); + } + } else if (pid == 0) { + fprintf(stdout, "Child (%d) \t Parent(%d)\n", getpid(), getppid()); + exit(EXIT_SUCCESS); + } else { + perror("fork"); + } + return EXIT_SUCCESS; +} -- GitLab