This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problems with pfstream.h


Hi,
 I apologize if this turns out to be a stupid question.

I can't get pfstream to release resources.  The output of this code on
my system is below (after the code listing).   Is there a way to free up
the file resources being used here?  Or is there a bug that causes the
close() in the destructor not to clean up properly?  Am I missing
something?

Thanks very much for a great compiler!

Bill

PS I'm running athena-ized red hat linux 4.2 on a 686

______________________________


#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <wait.h>
#include <sys/resource.h>
#include <pfstream.h>

int main () {

  struct rlimit rlm;
  int x = getrlimit(RLIMIT_NOFILE,&rlm);
  cout << "rlimit is "<<rlm.rlim_cur << " "<<rlm.rlim_max<<" returning
"<< x << endl;
  rlm.rlim_cur = 10;			// Set the limit low so we run into it quickly
  x = setrlimit(RLIMIT_NOFILE,&rlm);
  cout << x << " returned from setrlimit"<<endl;
  
  char restofline[1024];
  ipfstream *shellpipe = 0;  
  pid_t prid;
  int i,status;

  for (i=0;i<30;i++) {
	shellpipe = new ipfstream("|ls -al",ios::in);
	cout << "Opening number "<<i<<" errno = "<<errno<<endl;
	while (shellpipe->good()) {
	  shellpipe->getline(restofline,1023); // Get output from process
	  cout << restofline << endl;
	}
	prid = wait(&status);
	cout << "Process "<<prid<<" finished with status "<<status<<" and errno
= "<<errno<<endl;
 	delete shellpipe;
  }
}

______________________________________

rlimit is 256 256 returning 0
0 returned from setrlimit
Opening number 0 errno = 0
total 29
drwxr-xr-x   2 whall    mit          1024 Jun  3 17:17 .
drwxrwxr-x   3 whall    513          3072 Jun  3 17:17 ..
-rwxr-xr-x   1 whall    mit         24240 Jun  3 17:13 test

Process 15345 finished with status 0 and errno = 0
Opening number 1 errno = 0
total 29
drwxr-xr-x   2 whall    mit          1024 Jun  3 17:17 .
drwxrwxr-x   3 whall    513          3072 Jun  3 17:17 ..
-rwxr-xr-x   1 whall    mit         24240 Jun  3 17:13 test

Process 15346 finished with status 0 and errno = 0
Opening number 2 errno = 0
total 29
drwxr-xr-x   2 whall    mit          1024 Jun  3 17:17 .
drwxrwxr-x   3 whall    513          3072 Jun  3 17:17 ..
-rwxr-xr-x   1 whall    mit         24240 Jun  3 17:13 test

Process 15347 finished with status 0 and errno = 0
Opening number 3 errno = 0
total 29
drwxr-xr-x   2 whall    mit          1024 Jun  3 17:17 .
drwxrwxr-x   3 whall    513          3072 Jun  3 17:17 ..
-rwxr-xr-x   1 whall    mit         24240 Jun  3 17:13 test

Process 15348 finished with status 0 and errno = 0
Opening number 4 errno = 0
total 29
drwxr-xr-x   2 whall    mit          1024 Jun  3 17:17 .
drwxrwxr-x   3 whall    513          3072 Jun  3 17:17 ..
-rwxr-xr-x   1 whall    mit         24240 Jun  3 17:13 test

Process 15349 finished with status 0 and errno = 0
Opening number 5 errno = 0
total 29
drwxr-xr-x   2 whall    mit          1024 Jun  3 17:17 .
drwxrwxr-x   3 whall    513          3072 Jun  3 17:17 ..
-rwxr-xr-x   1 whall    mit         24240 Jun  3 17:13 test

Process 15350 finished with status 0 and errno = 0
Opening number 6 errno = 24
Process -1 finished with status 0 and errno = 10
Opening number 7 errno = 24
Process -1 finished with status 0 and errno = 10
Opening number 8 errno = 24
Process -1 finished with status 0 and errno = 10
Opening number 9 errno = 24

[and so on...]


-- 
William Hall
Draper Fellow, MIT Operations Research Center
mailto:whall@alum.mit.edu
http://snipe.mit.edu/bill/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]