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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:06:23+00:00 2026-05-10T23:06:23+00:00

Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time?

  • 0

Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time? That is the EAGAIN code, which is the same as WOULD BLOCK which means there is no data waiting to be read, but select is returning 1 saying there is data (tested in Linux):

#include <time.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/errno.h>  int main(int argc, char** argv) {     int fd = open('/dev/lp0', O_RDWR | O_NONBLOCK);     int ret = 0;     int status = 0;     char buffer[1024];     char teststr[] = 'This is a test\n';     char XMIT_STATUS_OFFLINE[] = {0x10,0x04,0x02};     char XMIT_STATUS_ERROR[] = {0x10,0x04,0x03};     char XMIT_STATUS_ROLL[] = {0x10,0x04,0x04};     char XMIT_STATUS_SLIP[] = {0x10,0x04,0x05};     fd_set rfds;     FD_ZERO( &rfds );     FD_SET( fd, &rfds );     struct timeval sleep;     sleep.tv_sec = 5;     sleep.tv_usec = 0;      /* Offline status */     ret = write(fd, XMIT_STATUS_OFFLINE, sizeof(XMIT_STATUS_OFFLINE));     //printf('write() returned %d\n', ret);      do {         ret = select( fd + 1, &rfds, NULL, NULL, &sleep );     } while (ret < 0 && (errno == EINTR));      ret = read(fd, buffer, 1024);     if(ret == -1) {         perror('read(): ');     } else {         status = buffer[0];         if((status & 0x04) != 0)         {             printf('The cover is open.\n');         } else {             printf('OFFLINE is good.\n');         }     }     close(fd);     return 0; } 
  • 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. 2026-05-10T23:06:24+00:00Added an answer on May 10, 2026 at 11:06 pm

    Your select call will return 0 after the 5 second timeout elapses if no data is available. Your code will ignore this and try to read from the device anyways. Check for ret == 0 and that will fix your problem.

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

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I was able to find absolute path to my DLL… May 11, 2026 at 8:58 am
  • added an answer of course some web browser windows may not be that… May 11, 2026 at 8:58 am
  • added an answer Certificates are cryptographically signed by something called a Certificate Authority(CA),… May 11, 2026 at 8:58 am

Related Questions

Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time?
Why does the following code sometimes causes an Exception with the contents CLIPBRD_E_CANT_OPEN: Clipboard.SetText(str);
Why does the following code not work as I was expecting? <?php $data =
Why does the following code NOT give an error, nor any type of a
Why does the following code in C work? const char* str = NULL; str
Does anybody know why the following code only has effect in FF? $(document).ready(function() {
Why does the following method hang? public void pipe(Reader in, Writer out) { CharBuffer
Why does the following behave unexpectedly in Python? >>> a = 256 >>> b
In MySQL 5.0 why does the following error occur when trying to create a
I don't understand, why does the following regular expression: ^*$ Match the string 127.0.0.1?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.