We are in the middle of grading Lab 8. In the mean time, take a look at one possible solution below:
int main() { // code removed for brevity : : } else { // loop through each commands, setup pipes. int i; int fd[2*MAX_PIPE_LENGTH]; for (i = 0; i < num_of_cmds; i++) { // for k cmds, there should be k-1 pipes. // the ith cmd reads from fd[2i-2], write to fd[2i+1]. if (i < num_of_cmds - 1) { pipe(&fd[2*i]); } pid = fork(); int read_from = (i<<1)-2; int write_to = (i<<1)+1; switch (pid) { case -1: perror("fork"); exit(1); case 0: if (i != 0) { if (dup2(fd[read_from], STDIN_FILENO) == -1) perror("dup2"); close(fd[read_from+1]); } if (i != num_of_cmds-1) { if (dup2(fd[write_to], STDOUT_FILENO) == -1) perror("dup2"); close(fd[write_to-1]); } execvp(args[i][0], args[i]); perror(args[i][0]); close(fd[read_from]); close(fd[write_to]); exit(1); default: if (i > 0) { if (close(fd[2*i-2]) == -1) { perror("close"); } if (close(fd[2*i-1]) == -1) { perror("close"); } } break; } } for (i = 0; i < num_of_cmds; i++) waitpid(-1, NULL, 0); } free(command); } return 0; }
Very interesting topic will bookmark your site to check if you Post more about in the future.
Love Spell for Vedic Astrologers
Very Gorgeous! Congrats And Long Live Happy Memories!
Financial problem solution in india
Some truly fantastic blog posts on this site, regards for contribution.!
Husband wife dispute problem solution In india
Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing…
Solve my love problem
Great Article it its really informative and innovative keep us posted with new updates. its was really valuable.
Black Magic Astrologer
Thanks for sharing.I found a lot of interesting information here. A really good post, very thankful and hopeful that you will write many more
Love Marriage Problem Solution in india
This post is really astounding one! I was delighted to read this, very much useful. Many thanks
Online Famous Muslim Astrologer
awesome post. I’m a normal visitor of your web site and appreciate you taking the time to maintain the nice site. I’ll be a frequent visitor for a long time.
Muslim Love Marriage Specialist Maulana ji
Very helpful information. Thanks for sharing this with us.
SEO Company In Jaipur
Wow, Great Wonderful Article Useful Information.
Love Spells In Hindi
I am very glad that I am one of the visitors of this great website.
Husband wife problem solution
Yeah! This is very interesting post. I look forward for seeking more on your website.
How can Stop Marriage of Lover
This particular article is really good.
Love Marriage Problem Solutions
I check your blog again and again. Best of luck for your new article.
Vedic astrology predictions
Wish you a good luck with best wishes. Your web page is excellent, carry on your good job.
Love Affair Problem Solution
Thank you so much for sharing such useful information. Everything is very precise explanation of the issues. It was truly informative.
Love astrology prediction
Thank you for posting this blog I was just worried about How to Write 10000 Words Dissertation on CSS, Your blog just sought out my problems.
The experts of Affordable Dissertation UK have been delivering 100% unique as well as cheap assignment writing help at a Low-cost in the UK. It is effortless to use affordable Dissertation UK for getting any solution from the experts for assignment writing difficulties.