Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the below C code to accomodate the following: Let the parent send the data to the child through the pipe. The data sent by

Modify the below C code to accomodate the following: Let the parent send the data to the child through the pipe. The data sent by the parent should be carrying all the integers in an array declared as shown here: int arr[10]={5,7,9,2,6,3,4,1,7,9} . Note the integers should be copied into the string and then sent. The child process should sum up all the integers and display the result. Insert the wait statement in the parent process so it should wait until the child terminates.

My question is the same except the question asks for the largest integer array instead. How do I go about implementing this?

#include

#include

#include

#include

int main(void)

{

int fd[2], nbytes;

pid_t childpid;

int users = 95;

char mystring[80];

char readbuffer[80];

char digit1,digit2;

digit1 = (char) users%10;

digit2 = (char ) users/10;

mystring[0] = digit1;

mystring[1] = digit2;

printf("%d %d ",mystring[0],mystring[1]);

pipe(fd);

if((childpid = fork()) == -1)

{

perror("fork");

exit(1);

}

if(childpid == 0)

{

/* Child process closes up input side of pipe */

close(fd[0]);

/* Send "string" through the output side of pipe */

write(fd[1], mystring, sizeof(mystring));

exit(0);

}

else

{

/* Parent process closes up output side of pipe */

close(fd[1]);

/* Read in a string from the pipe */

nbytes = read(fd[0], readbuffer, sizeof(readbuffer));

printf("Received string: %d %d ",readbuffer[0],readbuffer[1]);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

Match the attack to the mitigation. Malware spoofing

Answered: 1 week ago