By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

popen cannot allocate memory

P: n/a
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

Apr 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"rveloso" <rv******@gmail.com> writes:
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?


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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.