Question: Here i have C codes for a parent-children communication using a pipe, please answer me the below questions regarding the code you see. #include #include

Here i have C codes for a parent-children communication using a pipe, please answer me the below questions regarding the code you see.

#include

#include

#include

int main()

{

int pipefd[2];

pid_t pid1, pid2;

/* create the pipe */

pipe(pipefd);

/* fork child 1 */

pid1 = fork();

if(pid1 == 0)

{

/* child 1 */

close(pipefd[0]); /* close read end */

dup2(pipefd[1], 1); /* redirect stdout to pipe */

execlp("ls", "ls", "-F", (char*)NULL); /* execute */

}

/* fork child 2 */

pid2 = fork();

if(pid2 == 0)

{

/* child 2 */

close(pipefd[1]); /* close write end */

dup2(pipefd[0], 0); /* redirect stdin from pipe */

execlp("nl", "nl", (char*)NULL); /* execute */

}

/* parent process */

/* close both ends in parent */

close(pipefd[0]);

close(pipefd[1]);

/* wait for the 2 children to end */

wait(NULL);

wait(NULL);

/* message to mark end of parent process, can be commented out if not needed */

printf("Parent process end ");

return 0;

}

Here i have C codes for a parent-children communication using a pipe,

1. What form of exec() function you used? Why? 2. How many times you used fork? Why? 3. How many pipes this assignment required? Why? 4. What form of wait() you used? How many times

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!