Will answer your previous post after I get home. Seems an earlier attempt post didn't make it. I added a delay to the code; the code no longer failed.
for (i =0; i < 1000000; i++);
after popen, fgets (not sure)
Accuracy is important. So post the exact code when you can do so, rather than guess at it when unsure. And in general, posting complete code is better than posting code fragments that have to be manually edited or combined to produce a whole.
And in addition to my earlier question about OS version and gcc version, please identify the CPU architecture by choosing "About This Mac" from the Apple menu, and posting the exact value listed after Processor.