Old stuff/ecole_etude_fac_de_pau/licence_3/projet_commun_se/backup14/tireuses.c
(Deskargatu)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/shm.h>
#include "include/global.h"
#include "include/demandes.h"
#include "include/shm.h"
#include "include/tireuses.c"
#include "include/blonde.h"
#include "include/brune.h"
int main(int argc, char** argv)
{
pid_t pid;
if(setpgid(0,getpid()) == -1)
{
perror("tireuses setpgid");
exit(-1);
}
// Generation de la shm pour tout le monde
if ((id_shm = get_shm("./cle_bar",(void*)&flg)) == -1)
{
perror("tireuses.c: generation de la shm");
exit(-1);
}
if (*(int*)(flg+sizeof(flg)+3*sizeof(int)) != 0 || *(int*)(flg+sizeof(flg)+4*sizeof(int)) != 0)
{
perror("Les tireuses sont deja lancee?");
exit(-1);
}
printf("Loading tireuse blonde ...\n");
pid = fork();
if (pid == -1) { perror("main: Fork loop error"); exit(-1); }
else if(pid == 0) { go_blonde(); return (0); }
printf("OK\n");
printf("Loading tireuse brune ...\n");
pid = fork();
if (pid == -1) { perror("main: Fork loop error"); exit(-1); }
else if(pid == 0) { go_brune(); return (0); }
printf("OK\n");
printf("Loading tireuse SECU ...\n");
pid = fork();
if (pid == -1) { perror("main: Fork loop error"); exit(-1); }
else if(pid == 0) { securite(); return (0); }
printf("OK\n");
while(1) { pause(); }
return 0;
}