what is wrong with this simple problem

This is a discussion on what is wrong with this simple problem within the Linux Programming forums, part of the Platform Specific Boards category; What is wrong with the following code, there is no result ,just waiting, i do not know why that happens ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    4

    what is wrong with this simple problem

    What is wrong with the following code, there is no result ,just waiting, i do not know why that happens
    Code:
    int main(void) {
        int pid, mypipe[2];
        if(pipe(mypipe) == -1) {
            perror("pipe");
            exit(1);
        }
        pid = fork();
        if(pid > 0) {
            dup2(mypipe[0],0);
            close(mypipe[0]);
            execlp("wc","wc",NULL);
            perror("exec");
            exit(1);
        }
        if(pid == 0) {
            dup2(mypipe[1],1);
            close(mypipe[1]);
            execlp("ls", "ls", NULL);
            perror("exec");
            exit(1);
        }
        return 0;
    }

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Try posting in the Linux programming forum.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    I think you should write some debug information into a file (or two) so
    you can see what is going on. Flush the file after every write.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. simple JPEG problem
    By the bassinvader in forum C Programming
    Replies: 6
    Last Post: 10-05-2006, 05:45 PM
  3. arrays - simple problem
    By ademkiv in forum C Programming
    Replies: 2
    Last Post: 03-02-2006, 08:55 PM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM
  5. Simple Compile Time Problem - HELP!
    By kamikazeecows in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2001, 12:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21