|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Oct 2007
Messaggi: 80
|
[C][C++] quale errore?
è tutta la notte che cerco di fare questo semplice albero:
ho scritto questo codice: #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> int main(int argc, char *argv[]) { pid_t pid; int level; int fila; fila=0; for(level = 0; level <= 5; level++ ){ if (fork()==0){ // FIGLIO fila++; exit(0); } else //PADRE { if (fork()){ if (fork()){ fila++; } } } if (fila!=level) { if (fila%2==0) //FILE PARI { wait(); } else { pid_t wait(); } } else //ULTIMA FILA { sleep(30); } } cosa sbaglio????????? |
![]() |
![]() |
![]() |
#2 |
Member
Iscritto dal: Oct 2007
Messaggi: 80
|
allegato
ora ho messo anche l'allegato!
scusa! mentre gli errori che ricevo sono: arbol.c:in function 'main': arbol.c:34: error too few arguments to function wait; arbol.c:46: expected decleration or statement at the end of input. |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
- Alla wait() dovrai passare qualche parametro, altrimenti non sa per quale motivo aspettare;
- pid_t wait(); e' solo una dichiarazione di prototipo. E' proprio quello che volevi fare? Dubito! - Il numero di parentesi aperte/chiuse e' errato. Ne devi chiudere una piu', quantomeno. Cmq il programma che hai scritto non implementa l'albero di processi che avevi in mente. Suggerimento: devi per forza farlo con un solo ciclo?
__________________
In God we trust; all others bring data |
![]() |
![]() |
![]() |
#4 |
Member
Iscritto dal: Oct 2007
Messaggi: 80
|
è tutto il giorno che ci lavoro ma non ne vengo fuori..
ho sistemato il codice ma non mi funziona.. #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){ //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: 05:55.