|
Home > Archive > Unix Programming > April 2006 > popen cannot allocate memory
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
popen cannot allocate memory
|
|
| rveloso 2006-04-11, 9:59 am |
| Hi all, i'm having a really nasty problem with popen.
I have the following code :
---------------------
....
FILE *PD;
....
sprintf(fname[i],"/usr/bin/gzip -dc %s/%s",dirname,dp->d_name);
....
if((PD = popen(fname[i], "r"))==NULL){
fprintf(stderr,"%d: Failed opening pipe to %s\n",errno,fname[file]);
exit(-1);
}
....
pclose(PD)
....
---------------------
Now the popen is in a cycle and should open about 250 files in the same
dir.
The weird thing is that it always stops at file 100, no matter which
file it is, and I get the following
error message:
"12: Failed opening pipe ..."
doing perror 12 i get:
"Error code 12: Cannot allocate memory"
I don't understand why popen cannot allocate memory - any suggestion?
Thanks!
rveloso
| |
| Thomas Maier-Komor 2006-04-11, 9:59 am |
| rveloso wrote:
> Hi all, i'm having a really nasty problem with popen.
> I have the following code :
> ---------------------
> ...
> FILE *PD;
> ...
> sprintf(fname[i],"/usr/bin/gzip -dc %s/%s",dirname,dp->d_name);
> ...
> if((PD = popen(fname[i], "r"))==NULL){
> fprintf(stderr,"%d: Failed opening pipe to %s\n",errno,fname[file]);
> exit(-1);
> }
> ...
> pclose(PD)
> ...
> ---------------------
>
> Now the popen is in a cycle and should open about 250 files in the same
> dir.
> The weird thing is that it always stops at file 100, no matter which
> file it is, and I get the following
> error message:
> "12: Failed opening pipe ..."
> doing perror 12 i get:
> "Error code 12: Cannot allocate memory"
>
> I don't understand why popen cannot allocate memory - any suggestion?
> Thanks!
>
> rveloso
>
you are probably hitting the limit of open file descriptors. Check
ulimit, OPEN_MAX, and _SC_OPEN_MAX.
HTH,
Tom
| |
| Thomas Maier-Komor 2006-04-27, 7:55 am |
| Barry Margolin wrote:
> In article <e0t9ql$4ip$2@nnews.in.tum.de>,
> Thomas Maier-Komor <thomas@maier-komor.de> wrote:
>
>
> Actually, it's more likely that he's running into the limit on the
> number of stdio streams, which is often much lower and not configurable.
>
Taking the error message into account, you are probably right.
But:
maierkom@virunga:~$ uname -a
OSF1 virunga V4.0 1229 alpha
maierkom@virunga:~$ getconf STREAM_MAX
4096
maierkom@virunga:~$ getconf OPEN_MAX
4096
maierkom@anduril:~$ uname -a
SunOS anduril 5.10 Generic_118833-03 sun4u sparc SUNW,Sun-Blade-1000
maierkom@anduril:~$ getconf OPEN_MAX
256
maierkom@anduril:~$ getconf STREAM_MAX
256
On the above systems you will probably run first out of file descriptors
if you use both file descriptors and streams. BTW: I didn't expect
Linux's STREAM_MAX to be so low:
maierkom@zelda:~$ uname -a
Linux zelda 2.6.14-1.1644_FC4smp #1 SMP Sun Nov 27 03:39:31 EST 2005
i686 athlon i386 GNU/Linux
maierkom@zelda:~$ getconf STREAM_MAX
16
Cheers,
Tom
|
|
|
|
|