Advertisement

05.04.2004 at 09:58AM PDT, ID: 20977558
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8

PIPE PROBLEM AGAIN>>> MORE COMPLEX

Asked by silethunde in Linux Programming

Tags: , ,

Hi all!  Here's the problem... I want to open a file -> write its contents to a pipe -> pass the contents of the pipe to gzip or bzip2 -> give the output of gzip (or bzip2) to another pipe -> write the contents of the last pipe to a new file... This is my code... When I run it it hangs like its waiting for something... I guess there is a problem with a call to read() or something...


int zip(char* sourceFile,char* targetFile, int zipProgram)
{
     char* arg[3];
     
     pid_t fChildPid;
     pid_t sChildPid;

     int pipe1[2];
     int pipe2[2];
     
     pipe(pipe1);
     pipe(pipe2);
     
     if(zipProgram == 1)
          arg[0] = "/bin/gzip";
     else
          arg[0] = "/usr/bin/bzip2";

     arg[1] = "-c";
     arg[2] = NULL;
     
     fChildPid = fork();
     
     if(fChildPid == 0)
     {
         
          dup2(pipe1[R], STD_IN);
          dup2(pipe2[W], STD_OUT);
         
          close(pipe1[W]);
          close(pipe2[R]);

          execv(arg[0], arg);
     }
     else
     {
          sChildPid = fork();
          if(sChildPid == 0)
          {
               close(pipe2[W]);
               close(pipe1[R]);
               close(pipe1[W]);
               
               char buf[BUFFERSIZE] = {0};
               int target = open(targetFile, O_WRONLY | O_APPEND | O_CREAT |
                         S_IRWXU |
                         S_IRWXO |
                         S_IRWXG );    
               int count1;
               
               while((count1 = read(pipe2[R], buf, sizeof(buf))) > 0)
               {
                    write(target, buf, count1);
               }
               
               close(target);
               exit(1);
          }
                else
                {
                    int source = open(sourceFile, O_RDONLY);
                  char buf2[BUFFERSIZE] = {0};
                     int count2;
         
                        close(pipe1[R]);
                  close(pipe2[R]);
                  close(pipe2[W]);
               
                    while((count2 = read(source, buf2, sizeof(buf2))) > 0)
                 {
                     write(pipe1[W], buf2, count2);
                  }
     
                 close(source);
                 wait(&status);
                  }
     }
     return 0;
}

Can anyone see the problem?Start Free Trial
 
Loading Advertisement...
 
[+][-]05.04.2004 at 11:39AM PDT, ID: 10989565

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.04.2004 at 11:40AM PDT, ID: 10989577

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.04.2004 at 03:27PM PDT, ID: 10991619

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.05.2004 at 03:15AM PDT, ID: 10994550

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.05.2004 at 05:59AM PDT, ID: 10995565

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.05.2004 at 06:31AM PDT, ID: 10995790

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.08.2004 at 01:21PM PDT, ID: 11023104

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2004 at 01:27PM PDT, ID: 11023124

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Linux Programming
Tags: complex, piping, problem
Sign Up Now!
Solution Provided By: garboua
Participating Experts: 2
Solution Grade: B
 
 
[+][-]05.09.2004 at 04:05AM PDT, ID: 11025299

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.09.2004 at 06:07AM PDT, ID: 11025569

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43