my code it didn3939t run properly i tried to pass


My code it didn''t run properly ,i tried to pass 2 parameter example : ./a.out ls -ll ,but it execute only the ls instead of the ls -ll !
plz help amd thank you !
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

int main(int argc ,char *argv[])
{
int i,pid;
int fd[2];//crea i descriptor
char phrase[30][30];//crea il buffer
pipe(fd); /* crea la pipe */

for(i = 0; i < argc - 1 ; i++)
{
if((pid=fork())==0)
{
strcpy(phrase[i], argv[i+1]);
printf("ho scritoo :''%s''\n",phrase[i]);
close(fd[0]); /* chiude in lettura */
write(fd[1],phrase[i],strlen(phrase[i])+1); /* invia anche 0x00 */
close (fd[1]); // chiude in scrittura
// pid=0 -> figlio
usleep(50000*(1+i)); // Ritardo iniziale
printf("Figlio: %d\n",i+1); // Stampa messaggio del figlio
usleep(500000*(1+i)); // Ritardo finale
// Termina con codice di ritorno
dup2(fd[1], STDOUT_FILENO); // redirigo stdout sulla write end della pipe
//execlp(phrase[i], phrase[i], NULL); // eseguo il comando specificato
execlp(phrase[i],phrase[i],NULL);
return(101+i);
} else {
printf("Ho generato il figlio %d con pid %d\n",i+1,pid);
char message[100]; //creare il buffer
memset(message,0,100);
int bytesread;

bytesread = read(fd[0],message,sizeof(message));
printf("ho letto dalla pipe %d bytes: ''%s'' \n",bytesread,message);
// close(fd[0]);
}
}
close(fd[0]); /* chiude in scrittura */
close(fd[1]); /* chiude in scrittura */
// Attende che dieci processi terminino
for(i=0;i {
int status;
wait(&status); // Attende termine di un figlio (uno qualunque)
printf("Terminato processo %d\n",WEXITSTATUS(status));
}
return 0;
}

Request for Solution File

Ask an Expert for Answer!!
Operating System: my code it didn3939t run properly i tried to pass
Reference No:- TGS0413890

Expected delivery within 24 Hours