|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2004
Città: Rovereto (tn)
Messaggi: 2187
|
[C] Zombie
Salve gente,
ho un probelama, devo creare una sorta di shell, e devo implementare la & (che permette di continuare ad usare la shell anche quando si esegue un programma). il codice è più o meno così Codice:
pid=fork();
if (!pid){
execvp(argv[0],argv);
}
else {
/* se deve aspettare, la & non c'è */
if (f_wait) {
/* fa un wait sul figlio */
waitpid(pid,&status,0);
}
mi sono spiegato? come posso fare? |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Penso che basti leggere il valore di ritorno
__________________
In God we trust; all others bring data |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Oct 2004
Città: Rovereto (tn)
Messaggi: 2187
|
Quote:
|
|
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
__________________
In God we trust; all others bring data |
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Oct 2004
Città: Rovereto (tn)
Messaggi: 2187
|
io ho fatto così
Codice:
void controlla_figli(){
int pid,status;
do {
pid = waitpid(WAIT_ANY, &status, WNOHANG);
if (pid > 0) {
printf("%d DONE %x \n", pid, status);
}
} while (pid > 0);
}
Codice:
pid=fork();
if (!pid){
execvp(argv[0],argv);
}
else {
/* se deve aspettare, la & non c'è */
if (f_wait) {
/* fa un wait sul figlio */
waitpid(pid,&status,0);
}
controlla_figli();
}
si può fare in modo più corto? |
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: May 2002
Città: somewhere in Europe
Messaggi: 2554
|
Quote:
|
|
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
High Flying Sottovento
__________________
In God we trust; all others bring data |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 02:39.



















