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 !

Os structures, #question.explain varios types of system calls..

#question.explain varios types of system calls..

Linear programming problem, A paper mill produces two grades of paper viz.,...

A paper mill produces two grades of paper viz., X and Y. Because of raw material restrictions, it cannot produce more than 400 tons of grade X paper and 300 ton

Define race condition, Define race condition. When various process acce...

Define race condition. When various process access and manipulate similar data concurrently, then the outcome of the execution depends on certain order in which the access take

Advantages and disadvantages of thread, OPERATING SYSTEM 1. Describe th...

OPERATING SYSTEM 1. Describe the term operating system. Write down the functions of operating system. 2. Explain Thread? Write down the advantages and disadvantages of threa

Explain fixed partitioning techniques, FIXED PARTITIONING In a fixed p...

FIXED PARTITIONING In a fixed partitioning, the operating system inhabiting some fixed portion of main memory is available for use of multiple processes -Using fixed partit

Operation research, scattered resposibi;ity and authority -necessity of ope...

scattered resposibi;ity and authority -necessity of operation research

Virtual addresses, Virtual addresses are made up of two parts: the ?rst par...

Virtual addresses are made up of two parts: the ?rst part is the page number, and the second part is an offset inside that page. Suppose our pages are 4kb (4096 = 212 bytes) long,

Calculate maximum average bandwidth, You have a system with two primary wor...

You have a system with two primary workloads. One performs sequential access to a set of large files, the other performs small, independent, random reads to a separate set of large

Linux, Discuss the risks of having a single root user

Discuss the risks of having a single root user

Explain about interprocess communication, Explain about interprocess commun...

Explain about interprocess communication The cooperating processes communicate with each other via an interprocess communication facility. IPC gives a mechanism to permit proce

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