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 !

Paging, Paging full question

Paging full question

Disk scheduling algorithms-first come, FCFS (First Come, First Served) Per...

FCFS (First Come, First Served) Perform operations in order requested No reordering of work queue No starvation every demand is serviced Poor performance

Explain the various database applications used in linux, Question 1 Descri...

Question 1 Describe about the shells of Linux operating system Question 2 Describe briefly about GNOME desktop Question 3 Write note on the following- Encryp

Roles of operating systems, Describe Three major roles of operating systems...

Describe Three major roles of operating systems in business computer systems

What are a safe state and an unsafe state, What are a safe state and an uns...

What are a safe state and an unsafe state? Answer:  A state is safe if the system can allocate resources to every process in some order and still avoid a deadlock. A system is

Memory pages, Applications allocate memory in terms of the number of bytes ...

Applications allocate memory in terms of the number of bytes that they need, but this level of granularity is too ?ne-grained for the operating system to manage the system memory i

Define the dosexit function used in the os/2, Define the DosExit Function u...

Define the DosExit Function used in the OS/2 DosExit(action, resultCode)  DosExit function is to be called when a thread or process is finished executing. If EXIT_THREAD is

Assignment on Fork System Call, Parent process P creates three child proces...

Parent process P creates three child processes, C1, C2, and C3. Each child process executes a memory and CPU intensive application of your choice. Your choice should be such that

Define memory management, Define memory management In multiprogramming ...

Define memory management In multiprogramming system the user part of memory should be further subdivided to accommodate multiple processes. The task of subdivision is carried o

Explain chaining to handle collision, Explain Chaining to Handle Collision ...

Explain Chaining to Handle Collision Chaining:  One easy scheme is to chain all collisions in lists attached to the suitable slot. This permits an unlimited number of collision

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