title: How to fix fgets() hanging when reading popen()?
body: <p>I have been working on an Android app that does its functions in JNI. My problem is in a function where logcat displays until a button is pressed. I found where the problem occurs:</p>
  
  <pre><code>FILE *logcat = popen("su -c logcat threadtime", "r");
  
  while (isRunning(running, env, thiz))
      if (fgets(&amp;line, sizeof(line), logcat) != NULL) //&lt;--- HERE
          appendLogWithToken(logger, line, env, thiz);
  </code></pre>
  
  <p>I have done some debugging and found out that the <code>fgets()</code> sleeps until another line is received. I have searched and found similar questions but no working answers. Are there any other functions that return null and don't wait for input, or is this fixable?</p>