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 !

Batch oriented and interactive operating system., properies of Batch orient...

properies of Batch oriented and interactive operating system.

Kernel to context switch between kernel level threads, Q. Explain the actio...

Q. Explain the actions taken by a kernel to context switch between kernel level threads. Answer: Context switching among kernel threads classically requires saving the value

Explainoptimal page replacement in detail, Optimal page replacement An...

Optimal page replacement An optimal page replacement algorithm has the least page fault rate of all algorithms. The algorithm states that put back the page that will not be us

Explain the real time operating system, Explain the Real Time Operating Sys...

Explain the Real Time Operating System A real-time operating system comprises definite, fixed time constraints. Processing should be done in the defined constraints, or the sys

Explain second-chance algorithm, Second-Chance algorithm When a page ha...

Second-Chance algorithm When a page has been selected, we inspect its reference bit. If the value is 0, we proceed to replace this page. If the reference bit is set to 1, thoug

Computer number systems, Binary number based systems   Binary is a  ' base...

Binary number based systems   Binary is a  ' base 2' number system, only two numbers exist namely '0' and '1'. Conversion from binary to base 10 is easy if the number column techn

Bounded and unbounded buffer, Ask question #Minimum 100 difference between ...

Ask question #Minimum 100 difference between bounded and unbounded buffer words accepted#

Dynamically loadable kernel modules, Q. Dynamically loadable kernel module...

Q. Dynamically loadable kernel modules give elasticity when drivers are added to a system however do they have disadvantages too? Under what situations would a kernel be compiled

Explain about deadlock detection, Explain about deadlock detection? In ...

Explain about deadlock detection? In deadlock situation, the system must provide An algorithm that verifies the state of the system to verify whether a deadlock has occu

How many cubic feet of storage space would require, Q. Presume that we agr...

Q. Presume that we agree that 1 kilobyte is 1,024 bytes 1 megabyte is 1,0242 bytes and 1 gigabyte is 1,0243 bytes. This progression carries on through terabytes, petabytes, and ex

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