79709714

Date: 2025-07-21 23:27:47
Score: 0.5
Natty:
Report link

I ended up calling isStdoutReady() (below) before printf() and so far it appears to work. I have tested it with slow/intermittent upload connectivity to remote terminals and also manually by holding the scroll bar on Putty windows for 40+ sec to simulate a connectivity dropout.

Pros

Cons

@Kaz and @LuisColorado if you can edit your answers and combine with a poll() method like this or similar, I can accept and delete this answer.

int isStdoutReady() {

struct pollfd pfd;
int ret_val;

   pfd.fd = STDOUT_FILENO;
   pfd.events = POLLOUT;
   pfd.revents = 0;

   if ((ret_val = poll(&pfd, 1, 1)) > 0) {  /* timeout (in msec) is 3rd param; if set to zero will return immediately */

      if (!(pfd.revents & POLLOUT)) return 0;  /* if POLLOUT not set then stdout not ready for writing */

      if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) return -1;  /* handle errors or hang-ups */
   }
   else if (ret_val < 0) return -1;  /* error value:  EINVAL, EAGAIN, EINTR */
   else return 0;  /* poll() return value zero is a time-out */

   return 1;  /* stdout ready for writing */
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Kaz
  • User mentioned (0): @LuisColorado
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Jeff Brower