title: Correct way of reading /proc/pid/status
body: <p>I read <code>/proc/&lt;pid&gt;/status</code> this way:</p>
  
  <pre><code>std::ifstream file(filename);
  std::string line;
  int numberOfLinesToRead = 4;
  int linesRead = 0;
  
  while (std::getline(file, line)) {
      // do stuff
      if (numberOfLinesToRead == ++linesRead) {
          break;
      }
  }
  </code></pre>
  
  <p>I noticed that in rare cases <code>std::getline</code> hangs. </p>
  
  <ol>
  <li>Why it happens? I was under impression that proc filesystem should be in somewhat consistent state and there should not be cases when newline is missing. My assumption was that <code>getline</code> returns <code>false</code> when EOF/error occurs.</li>
  <li>What is the recommended, <em>safe</em> way to read <code>/proc/&lt;pid&gt;/status</code> ? </li>
  </ol>