2

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.

WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • Er? Where does pipe(2) refer me to fork(2)? And why would fork()'s errors be relevant for pipe()? – bdonlan Jun 21 '11 at 02:37
  • Oops, thanks for catching that, it is popen, not pipe. – WilliamKF Jun 21 '11 at 02:41
  • 1
    What does [`strace(1)`](http://linux.die.net/man/1/strace) say is happening? `popen(3)` calls `pipe(2)` and `fork(2)` internally; which call is returning `ENOMEM`, `pipe` or `fork`? – Adam Rosenfield Jun 21 '11 at 02:44
  • I'm pretty sure I'm leaking the file descriptors and that is causing the failure. – WilliamKF Jun 21 '11 at 04:10
  • while running your application also run "top" command in another terminal and check if there is any high memory consumption. – Arunmu Jun 21 '11 at 04:27

1 Answers1

1

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

WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • 1
    The documentation suggests that should be `EMFILE` or `ENFILE`, not `ENOMEM`. I think you should take @Adam's suggestion and run it under strace to find out which system call actually gave the error, because this sounds very weird. – Nemo Jun 21 '11 at 16:23