diff --git a/rendu/process_basics.c b/rendu/process_basics.c new file mode 100644 index 0000000..d485fc0 --- /dev/null +++ b/rendu/process_basics.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_basics.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ruiferna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/10/14 17:06:42 by ruiferna #+# #+# */ +/* Updated: 2025/10/14 19:53:46 by ruiferna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +#define NUM_CHILDREN 3 + +int main(int argc, char *argv[]) { + pid_t pids[NUM_CHILDREN]; + int i; + + i = 0; + while (i < NUM_CHILDREN) + { + pids[i] = fork(); + if (pids[i] == -1) { + printf("Error creating process\n"); + return 1; + } + if (pids[i] == 0) { + // Child process + int child_id = i + 1; + int j; + j = 0; + while (j <= 5) + { + printf("Child %d (PID: %d): Message %d\n", child_id, getpid(), j); + usleep(100000); + j++; + } + exit(0); + } + i++; + } + + // Parent process + i = 0; + while (i < NUM_CHILDREN) + { + waitpid(pids[i], NULL, 0); + i++; + } + printf("Parent: All 3 children have finished\n"); + return (0); +} + diff --git a/subjects/13_process_basics.txt b/subjects/12_process_basics.txt similarity index 100% rename from subjects/13_process_basics.txt rename to subjects/12_process_basics.txt diff --git a/subjects/14_semaphore_basics.txt b/subjects/13_semaphore_basics.txt similarity index 100% rename from subjects/14_semaphore_basics.txt rename to subjects/13_semaphore_basics.txt diff --git a/subjects/15_process_communication.txt b/subjects/14_process_communication.txt similarity index 100% rename from subjects/15_process_communication.txt rename to subjects/14_process_communication.txt diff --git a/subjects/16_process_termination.txt b/subjects/15_process_termination.txt similarity index 100% rename from subjects/16_process_termination.txt rename to subjects/15_process_termination.txt diff --git a/subjects/17_process_philosophers.txt b/subjects/16_process_philosophers.txt similarity index 100% rename from subjects/17_process_philosophers.txt rename to subjects/16_process_philosophers.txt diff --git a/subjects/18_philosophers_bonus.txt b/subjects/17_philosophers_bonus.txt similarity index 100% rename from subjects/18_philosophers_bonus.txt rename to subjects/17_philosophers_bonus.txt