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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:47:13+00:00 2026-05-26T02:47:13+00:00

I’m writing a C++ program for class that requires a set of N child

  • 0

I’m writing a C++ program for class that requires a set of N child processes to communicate with their parent process on a Unix-based system. To that end, I declared two arrays of N pipes, one for each direction of communication, before forking the process:

int pipesToParent[N][2];
int pipesToChild[N][2];

... // for int i = 0 to N-1, pipe(pipesToParent[i]), pipe(pipesToChild[i]),
    // fork(), yada yada, I included error checking and everything.

int pipesToChild[N][2];

Most of the code for the parent process is in a while loop; near the beginning of this loop, it reads a message from a particular process:

read(pipesToParent[processToServe][READ_END], charArray, BUF_SIZE);

The first time it goes through the loop, reading a message from process X, it works fine. Then it’s instructed to do the same for process Y, the message from which contains exactly the same sort of data as process X (I have each process cout its message when it writes it to its pipe), and the process just stops. It doesn’t exit, it just stays frozen at that line. I’ve tried everything I can think of to figure out what might be wrong with the message I’m sending, but it all looks just fine. What’s going on here?

(Sorry if my detail’s insufficient; I couldn’t figure out what else I’d have to include and what I could remove to paste something that’d reproduce the problem.)

ETA:

The child process has its own internal while loop, in which it reads from its own pipe:

read(pipesToChild[thisProcessNumber][READ_END], charArray, BUF_SIZE);

If the parent’s ready, it’ll send its message:

write(pipesToParent[thisProcessNumber][WRITE_END], message, BUF_SIZE);

Some tinkering has revealed that process Y, much like the parent, is going through this loop once fine, then getting stuck on the read the second time. What exactly would flushing do, and can I do it if I wrote to/read from the pipe this way? (If it’s relevant, I’ve #included cstdlib, but not cstdio.)

  • 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-05-26T02:47:14+00:00Added an answer on May 26, 2026 at 2:47 am

    Seems like deadlock to me – both your processes are waiting for another one to
    write something – but none of them actually writes anything, so everything stops. Make sure that your comunication design is deadlock-free (eg. clients reding conantly and writing only on reading READY comunicate, and server reading only fter writing READ comunicate). You might also consider going to non-blocking pipes.

    As far as i know pipes created with pipe() call are unbuffered – the only buffer involved is pipe buffer, but as this is the same buffer from which reading in target app is done, it cannot create comunnication problems. Application-level happens only if you map file descriptors to C-like FILE pointers, but it seems it’s not the case.

    If you still think that everything is ok, post minimal compilable code that shows this behavior, so I can perhaps say more.

    EDIT:

    Since you accepted an answer, it would be nice if you mentioned also which solution (if any) solved your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post

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.