|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Oct 2007
Messaggi: 80
|
[C][C++] semplice gestione processi
hola!
.. non ne vengo proprio fuori.. come faccio a costruire l'albero presente in allegato?(i numeri e l'ordine dei processi puo' cambiare.. insomma.. riuscire a costruire qlcs che ci assomigli!) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main(int argc, char *argv[]){ ..pid_t pid; ..int uscita,pidf1,pidf2,status; ..int fila, nivel; ..fila=0;//fila comincia da 0 fino ad arrivare all'altezza voluta che è "nivel" ..printf("escribes el nivel: "); ..scanf(" %d", &nivel);//ricevo in input nivel ..while(nivel==fila){ //SERVE UN WHILE? UN FOR? SOLO IF/THIS? NON CI CAPISCO PIU'.. //FIGLIO ....if(fork()==0) { ......fila++; ......exit(0); ....} ....else { //PADRE ......if(fork()) { ........if(fork()) { ......} ....} ....wait(&status); ....fila++; ..} //SE LA FILA E' PARI: ..if (fila!=nivel) { ...if ((fila%2)==0) { ......wait(&status); ......}else{ ........pid_t wait(); ......} ....} //ULTIMA FILA ....else{ ......sleep(30); ....} ..} } //senza puntini: (per fare copia/incolla per il buon uomo che vuole provarlo) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main(int argc, char *argv[]){ pid_t pid; int uscita,pidf1,pidf2,status; int fila, nivel; fila=0; printf("escribes el nivel: "); scanf(" %d", &nivel); while(nivel==fila){ //FIGLIO if(fork()==0) { fila++; exit(0); } else { //PADRE if(fork()) { if(fork()) { } } wait(&status); fila++; } //SE LA FILA E' PARI: if (fila!=nivel) { if ((fila%2)==0) { wait(&status); }else{ pid_t wait(); } } //ULTIMA FILA else{ sleep(30); } } } |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 18:19.



















