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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:54:25+00:00 2026-05-18T02:54:25+00:00

I’m working on some code involving pipes. The idea is that I’m supposed to

  • 0

I’m working on some code involving pipes. The idea is that I’m supposed to have a process looping indefinitely and add data to the pipe as it comes (I’m testing this by reading a file, and going line by line in a while loop).

If I set the other process (the one that reads the pipe) to sleep so the entire file is read I have no problems and get all the file in the output. As soon as I remove the sleep (so now the 2 processes start simultaneously with the 2nd process reading the information off the pipe as it comes), my code goes straight to the else block of my code below and I never see any actual output. What am I doing wrong?

close(pipe[1]);  
sleep(5);

while (1) {

  nbytes = read(pipe[0], buffer, 200);    

  if(errno != EWOULDBLOCK) {      
    printf("%s", buffer);     
  }

  else {
    printf("I am not blocked here\n");
    sleep(1);
  }
} 

Thanks

  • 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-18T02:54:25+00:00Added an answer on May 18, 2026 at 2:54 am

    Two things:

    1. did you make pipe[0] non-blocking? It’ll be something like int nbio=1; ioctl(pipe[0], FIONBIO, &nbio);
    2. you’re checking for error wrong.
    if(nbytes > 0) {
        /* you may need to null-terminate the input buffer prior to display */
        buffer[nbytes] = '\0';
        printf("%s", buffer);
    }
    else if(errno == EWOULDBLOCK) {
        printf("I am not blocked here\n");
        sleep(1);
    }
    else {
        printf("some other error occurred - if nbytes == 0, then it's EOF.\n");
    }
    

    probably errno is EWOULDBLOCK the first time through, and then doesn’t get updated on successful read, so it looks like EWOULDBLOCK again.

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

Sidebar

Related Questions

No related questions found

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.