From 2c5abe421b7a1b92081e38f6b1f04d407fcba834 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 15 Feb 2020 01:47:26 +0100 Subject: philo_one small refactoring, philo_three draft --- philo_three/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 philo_three/main.c (limited to 'philo_three/main.c') diff --git a/philo_three/main.c b/philo_three/main.c new file mode 100644 index 0000000..5c9b869 --- /dev/null +++ b/philo_three/main.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/15 00:45:24 by cacharle #+# #+# */ +/* Updated: 2020/02/15 01:40:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "philo_three.h" + +int main(int argc, char **argv) +{ + t_philo_args philo_args; + sem_t *forks; + + if (!parse_args(&philo_args, argc, argv)) + return (1); + forks = sem_open("philo_two", O_CREAT, 0700, philo_args.philo_num); + if (forks == SEM_FAILED) + return (1); + + i = -1; + while (++i < philo_args.philo_num) + { + pid = fork(); + if (pid == -1) + return (1); + if (pid == 0) + { + child_start(&philo_args); + return (0); + } + } + + sem_close(forks); + sem_unlink("philo_two"); + return (0); +} -- cgit