Inter-process Communication !, Operating System

Assignment Help:
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;
}

Related Discussions:- Inter-process Communication !

What are conditions under which a deadlock situation arise, What are condit...

What are conditions under which a deadlock situation may arise? A deadlock situation can arise if the following four conditions hold simultaneously in a system: a. Mutual ex

Define computer system environment, Q. List three instances of deadlocks th...

Q. List three instances of deadlocks that aren't related to a computer system environment. Answer: Two cars passage a single-lane bridge from opposite directions.

What are tree-structured directories, What are Tree-structured directories ...

What are Tree-structured directories We can generalize the directory structure to a tree of arbitrary height. This permits the user to create their own sub directories and to c

In which page replacement policy balady’s anomaly occurs, In which page rep...

In which page replacement policy Balady’s anomaly occurs? FIFO (First in First Out)

Program that will input an interger target value, When you turn in an assig...

When you turn in an assignment to be graded in this class, you are making the claim that you neither gave nor received assistance on the work you turned in (except, of course, assi

Operating systems structures, with the aid of diagrams describe the followi...

with the aid of diagrams describe the following OS structure monolithic,layered and client server.

Producer - consumer synchronization, This assignment is based on Programmin...

This assignment is based on Programming Project 6.40 in Silbershatz. Implement the ProducerXConsumer program according to the instructions for Project 6.40 for both Linux and Win32

Memory management, what is segmentation as it refers to operating system

what is segmentation as it refers to operating system

Network operating system, what is network operating? explain about it desig...

what is network operating? explain about it design issues?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd