int main(int argc,char **argv) { struct processus_info * p = get_processus_info_addr(); struct terminaux_info * t = get_terminaux_info_addr(); p->p_terminaux = getpid(); int j; initGet(18, "lo41"); /* création des 12 files*/ for(j = 1; j < 13; j++) { creation_file(j); } /* On remplit les files de chaque terminal de 3 camions */ for (j = 0; j < 36; j++) { t->term_to_load = j % 12 + 1; V(S_GEN_CAMION); P(S_TERMINAUX); } /* On lance les 12 terminaux, pour les mettre en attente d'autorisation de chargement du contrôleur*/ for (j = 0; j < 12; j++) { V(S_TERMINAUX); } sleep(1); /* Lancement des terminaux dans des processus fils, créés par fork() */ if ( ( p->pid_t1 = fork() ) == 0 ) { p->pid_t1 = getpid(); terminal(1); exit(0); } if ( ( p->pid_t2 = fork() ) == 0 ) { p->pid_t2 = getpid(); terminal(2); exit(0); } if ( ( p->pid_t3 = fork() ) == 0 ) { p->pid_t3 = getpid(); terminal(3); exit(0); } if ( ( p->pid_t4 = fork() ) == 0 ) { p->pid_t4 = getpid(); terminal(4); exit(0); } if ( ( p->pid_t5 = fork() ) == 0 ) { p->pid_t5 = getpid(); terminal(5); exit(0); } if ( ( p->pid_t6 = fork() ) == 0 ) { p->pid_t6 = getpid(); terminal(6); exit(0); } if ( ( p->pid_t7 = fork() ) == 0 ) { p->pid_t7 = getpid(); terminal(7); exit(0); } if ( ( p->pid_t8 = fork() ) == 0 ) { p->pid_t8 = getpid(); terminal(8); exit(0); } if ( ( p->pid_t9 = fork() ) == 0 ) { p->pid_t9 = getpid(); terminal(9); exit(0); } if ( ( p->pid_t10 = fork() ) == 0 ) { p->pid_t10 = getpid(); terminal(10); exit(0); } if ( ( p->pid_t11 = fork() ) == 0 ) { p->pid_t11 = getpid(); terminal(11); exit(0); } if ( ( p->pid_t12 = fork() ) == 0 ) { p->pid_t12 = getpid(); terminal(12); exit(0); } /* Sémaphore initialisation passée */ V(S_INIT); signal(SIGINT, fin_processus); /* Attente des processus fils */ waitpid(p->pid_t1, NULL, 0); waitpid(p->pid_t2, NULL, 0); waitpid(p->pid_t3, NULL, 0); waitpid(p->pid_t4, NULL, 0); waitpid(p->pid_t5, NULL, 0); waitpid(p->pid_t6, NULL, 0); waitpid(p->pid_t7, NULL, 0); waitpid(p->pid_t8, NULL, 0); waitpid(p->pid_t9, NULL, 0); waitpid(p->pid_t10, NULL, 0); waitpid(p->pid_t11, NULL, 0); waitpid(p->pid_t12, NULL, 0); return 0; }
void * funcao_principal(void *ptr){ creation_file(*(int *) ptr); }