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 43 44 45 46 47 48
|
void
execution(instruction inst,processus **proc)
{
pid_t pid;
int wait_status;
if (inst==NULL) return;
pid=fork();
if (pid==-1) {
printf("Erreur dans la creation du fils : %s",strerror(errno));
return;
}
// FILS
if (pid==0) {
printf("\nPid pere : %d\n",getppid());
if(strcmp(inst->cde,"cd")==0) {
printf("CD A CODER\n");
}
else if(strcmp(inst->cde,"jobs")==0) {
afficher_jobs(*proc);
}
else {
execvp(inst->cde,inst->argument);
printf("Erreur dans l'execution de la commande %s\n",strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
// PERE
} else {
printf("\nPid fils: %d\n",pid);
// Execution avec un & (en tache de fond)
if(inst->continuer) {
ajouter_job(inst,proc,pid);
execution(inst->suivant,proc);
} else {
ajouter_job(inst,proc,pid);
LA -> while(estpresent_job(pid)) { }; // En attente que sig_chld retire le jobd de la liste
}
}
execution(inst->suivant,proc);
} |
Partager