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 8615715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:26:51+00:00 2026-06-12T05:26:51+00:00

I have a parent process with two child processes fork’d off from it. I’ve

  • 0

I have a parent process with two child processes fork’d off from it. I’ve created two pipes(one for each child). For each pipe, I have closed the write end of the parent and the read ends of the children.

The problem I am having is getting the parent to simultaneously read from each child pipe. It appears to be only reading from the first pipe I try to read from.

//PARENT
while(1)
{
    read(fd[0], buffer, sizeof(buffer));
    //print out buffer
    read(fd2[0], buffer2, sizeof(buffer2));
    //print out buffer2
}

The only thing printing is the info from my first read call. I’ve concluded that read seems to be blocking the other read. I’ve looked online and found a possible solution in select, but could not figure out how to implement it with pipes(doesn’t seem to be any examples anywhere).

Could someone explain how select works with pipes or notify me of any other possible solutions to my problem?

  • 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-12T05:26:52+00:00Added an answer on June 12, 2026 at 5:26 am

    Your read is blocking. This means that when you call read, it waits until it either has the number of bytes you’ve requested or the stream is closed (hits EOF).

    You either need to make the pipe non-blocking (use fcntl(fd[0], F_SETFL, O_NONBLOCK);) or use threads.

    Edit add Jonathan Leffler’s point:

    If you do use non-blocking it would be most efficient to call select(). This will save you wasting a lot of CPU time (which is what would happen when you enable non-blocking since the reads would immediately return when no data is present). For instance:

    int fds[2];
    ...
    fds[0] = fd[0];
    fds[1] = fd2[0];
    
    while...
        select(2, &fds, NULL, NULL, NULL);
        read(...);
        read(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two processes using fork(). The child process is producing and writing
I have two executables - parent process and it's child process, running in a
I have two objects, and one inherites from the other. the parent object sends
I have a parent and a child process written in C language. Somewhere in
i have a parent form, it will have two tabs calling the two child
I have two scripts parent.sh and child.sh. There is a variable in parent.sh which
I have a parent process that forks two children. I need to force a
I have one package that calls two other child packages. All three packages have
i have to write program, which will create two child processes These processes would
i have two son processes that read from a file and send the results

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.