popen cannot allocate memory

R

rveloso

Hi all, i'm having a really nasty problem with popen.
I have the following code :
---------------------
....
FILE *PD;
....
sprintf(fname,"/usr/bin/gzip -dc %s/%s",dirname,dp->d_name);
....
if((PD = popen(fname, "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
 
K

Keith Thompson

rveloso said:
Hi all, i'm having a really nasty problem with popen.
I have the following code :
---------------------
...
FILE *PD;
...
sprintf(fname,"/usr/bin/gzip -dc %s/%s",dirname,dp->d_name);
...
if((PD = popen(fname, "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?


popen() is not a standard C function.

Some systems may impose limits on the number of files you can open
simultaneously. It's not clear from your code fragment whether you
close each file before opening a new one.

Both topics are more appropriate for comp.unix.programmer.

When you post there, it would be a good idea to post a complete,
self-contained program that illustrates the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top