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

  • SEARCH
  • Home
  • 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 7722851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:17:39+00:00 2026-06-01T04:17:39+00:00

//child process char buf[20]; read(fd[0][0], buf, 20); printf(%s, buf); //parent process write(fd[0][1], 12, 20);

  • 0
 //child process
    char buf[20];
    read(fd[0][0], buf, 20);
    printf("%s", buf);     

 //parent process
    write(fd[0][1], "12", 20);
    write(fd[0][1], "14", 20);
    write(fd[0][1], "15", 20);

 --output--
    12
    //then the program just exit. It cannot print out 14 and 15.

May I know that how can solve this problem? Can I make the child process waiting until it really read data from pipe?

I edited my program. And it can read all the data. However, the program just stop. It cannot continue to process. I think that it stop in the child process.

 //child process
    buf[6];
    int i;
    while ((i = read(fd[0][0], buf, 6)) > 0) {
         printf("%s", buf);     
    }

 //parent process
    write(fd[0][1], "12", 2);
    write(fd[0][1], "14", 2);
    write(fd[0][1], "15", 2);
    printf("done!\n");

 --output--
    121415done
  //The program just stopped in child process.
  • 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-01T04:17:40+00:00Added an answer on June 1, 2026 at 4:17 am
    static const int BUF_SIZE = 4;
    char buf[BUF_SIZE];
    
    ssize_t read_bytes;
    int i;
    
    while ((read_bytes = read(fd[0][0], buf, BUF_SIZE)) > 0) {
        printf("BUF: {\n'");
    
        for (i = 0; i < read_bytes; ++i) {
            if (buf[i] != '\0')
                putchar(buf[i]);
        }
    
        printf("'\n} : EOBUF[%d]\n", nbytes);
    }
    
    if (read_bytes < 0) {
         perror("FAIL");
    }
    

    Edit: Works bad if write size is > write data tho. Garbage at end.

    • read ssize_t read(int fildes, void *buf, size_t nbyte);
    • write ssize_t write(int fildes, const void *buf, size_t nbyte);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent and child process, and the parent can read output from
Here is a small piece of code, the parent process write pipe and child
I have a program with a parent and a child process. Before the fork(),
I am trying to write a c++ program that creates a child process, runs
I have a parent and a child process written in C language. Somewhere in
I'm writing a wrapper that forks an execv() process. Output from the child is
I am exploring parent process & child processes concept in UNIX. I wrote this
The aim of the program is to fork a new child process and execute
My program basically runs a executable file with command line arguments. A child process
When a child is forked from a parent process, all the variables from the

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.