title: Why is my popen failing
body: <p>My c code is </p>
  
  <pre><code>size_t n=0;
  char *str = (char *)malloc(sizeof(char)* 1000)
  FILE *fp = popen(" cat /conf/a.txt" ,"r" );
  // my program comes in this function only if /conf/a.txt exists
  
  getline(&amp;str, &amp;n, fp); &lt;== crash if fp is null 
  </code></pre>
  
  <p>My debugger shows that sometimes i get fp as null and hence my program crashes at line 6 . Sometimes i get valid pointere and it passes . </p>
  
  <p>What is it , that controls this behaviour . I can't find problem in above code . Some help is appreciated . </p>
  
  <p>I know I can have a check of fp==null but that is not my question . I just want to know , knowing that file is definitely present why is fp coming as null in some scenarios . </p>
  
  <p>man of popen says <code>The popen() function returns NULL if the fork(2) or pipe(2) calls fail, or if it cannot allocate memory.</code></p>
  
  <p>i checked after crash and system is having enough memory ..</p>