Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:14:01+00:00 2026-06-01T07:14:01+00:00

The program can read all the data from the pipe. However, the program just

  • 0

The program can read all the data from the pipe. However, the program just stop. It cannot continue to process. I think it stop in the child process.

//I created two pipe before fork (fd[0] and fd[1]).
//child process
if(pid == 0){
    close(fd[a][1]);
    buf[6];
    int i;
    while ((i = read(fd[a][0], buf, 6)) > 0) {
        printf("%s", buf);     
    }
    close(fd[a][0]);
exit(0); 
}

//parent process
write(fd[a][1], "12", 2);
write(fd[a][1], "14", 2);
write(fd[a][1], "15", 2);
write(fd[b][1], "12", 2);
write(fd[b][1], "14", 2);
write(fd[b][1], "15", 2);
printf("done!\n");
close(fd[0][1]);
close(fd[1][1]);
wait(NULL);
printf("Really done!!!\n");
...                      // The program cannot run after wait(NULL);

--output--
121415done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:14:02+00:00Added an answer on June 1, 2026 at 7:14 am

    You are issuing read in a while loop, effectively blocking yourself until something goes wrong. If you need to read 6 characters, this is how you would write the child process:

    char buf[7];
    int left = 6;
    int so_far = 0;   // instead of so_far, (6 - left) could also be used
    while (left > 0)
         int num_read = read(fd[0][0], buf + so_far, left);
         left -= num_read;
         so_far += num_read;
    }
    buf[so_far] = '\0';
    printf("%s\n", buf);     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI all. I am trying to make little program that reads data from file
I am trying to read unbufferd data from a pipe in Perl. For example
I have a program that needs to read data from a number of sources.
I created a SQLite database on Android device. The program can read/write to database
I'm doing a theatrical performance, and I need a program that can read images
Question #3 for the day. I've got to design a program that can read
after some processing my program shows a messagebox saying you can read a log
my C# application reads data from special USB device. The data are read as
I developed my own log processing program. To process logs originated from printk() ,
I am trying to create a program whereby i import data from an excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.