Question: Modify the program below to pass -l option to the ls command. /*Sample C program for Lab 3*/ #include #include #include #include //main int main()

Modify the program below to pass -l option to the ls command.

/*Sample C program for Lab 3*/ #include #include #include #include //main int main() { int fds[2]; pipe(fds); /*child 1 duplicates downstream into stdin */ if (fork() == 0) { dup2(fds[0], 0); close(fds[1]); execlp("more", "more", 0); } /*child 2 duplicates upstream into stdout */ else if (fork() == 0) { dup2(fds[1], 1); close(fds[0]); execlp("ls", "ls", 0); } else { /*parent closes both ends and wait for children*/ close(fds[0]); close(fds[1]); wait(0); wait(0); } return 0; }

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!