Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo_bonus/ft_start_bonus.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_start_bonus.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/23 00:07:59 by yabtaour #+# #+# */
9
/* Updated: 2022/05/23 00:08:01 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers_bonus.h"
13
14
void ft_create_philos(t_data *data, int *pid)
15
{
16
int i;
17
18
i = 0;
19
while (i < data->philos_num)
20
{
21
pid[i] = fork();
22
if (pid[i] == 0)
23
ft_start_philosophers(data, i);
24
i++;
25
}
26
}
27
28
int ft_start(t_data *data)
29
{
30
int i;
31
32
i = 0;
33
data->pid = malloc(sizeof(int) * data->philos_num);
34
if (!data->pid)
35
{
36
free(data);
37
exit(1);
38
}
39
ft_create_philos(data, data->pid);
40
while (i < data->philos_num)
41
waitpid(data->pid[i++], 0, 0);
42
ft_end(data);
43
return (1);
44
}
45
46