Causes for ENOMEM from ::popen()

2019-05-26 02:15发布

问题:

I have an application that mostly works, but am having one condition wherein the call to ::popen() gets an error with errno set to ENOMEM. The man page for ::popen() refers you to page for ::fork() which itself lists ENOMEM with this brief comment on Linux:

   The fork() function may fail if:

   ENOMEM Insufficient storage space is available.

I am wondering if I am really running out of memory, or perhaps some other resource like file descriptors? Can fork() give ENOMEM for something other than running out of actual memory on your system? This is Centos4.

回答1:

I have confirmed that the ENOMEM resulted from not calling ::pclose() after repeated ::popen() and eventually running out of file descriptors.