aboutsummaryrefslogtreecommitdiff
path: root/philo_three/main.c
blob: 5c9b8699f12d9aab7c5ecfbe9bf155f7e427cc43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   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);
}