From owner-freebsd-hackers Sun Jun 10 5:56:54 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from dove.cc.ncu.edu.tw (dove.cc.ncu.edu.tw [140.115.17.111]) by hub.freebsd.org (Postfix) with ESMTP id 1DDEE37B401 for ; Sun, 10 Jun 2001 05:56:31 -0700 (PDT) (envelope-from mihs@wmlab.csie.ncu.edu.tw) Received: from mihs (mihs.wmlab.csie.ncu.edu.tw [140.115.156.42]) by dove.cc.ncu.edu.tw (8.11.2/8.11.2/dove/0.0.4) with SMTP id f5ACxwn27999 for ; Sun, 10 Jun 2001 20:59:59 +0800 (CST) Message-ID: <001901c0f1ac$cb716890$2a9c738c@mihs> From: "Ming-I Hsieh" To: Subject: a bug in ipfstream under FreeBSD 4.3-RELEASE? Date: Sun, 10 Jun 2001 20:56:39 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2462.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In one case, I need to analyse the data flow of FreeBSD box. Therefore, I uses ipfstream to get report from 'ipfw show'. After program runs several days, I notes some odd number in kern.openfiles. I uses fstat to find out what thing is happened. Then I find my program does *not* release the fd after the ipfstream has droped. Now I uses popen and pclose to replace ipfstream. It works fine. Anyone know what thing happens? Is it a bug for pfstream? Or just my fault. The testing program is below. Thanks. //-------------------------------------------------------------------------- - // pfstream bug? //-------------------------------------------------------------------------- - #include #include #include #include #include #include //-------------------------------------------------------------------------- - int main(int argc, char ** argv) { if (argc < 3) { cerr.form("Usage: %s trynum sleep_time\n", argv[0]); return EX_USAGE; } register int i = 0, iend = atoi(argv[1]); for (i = 0; i < iend; i++) { ipfstream pfin("|/bin/ls /bin", ios::in); char buffer[1024]; // Read data from pfin while (pfin.getline(buffer, 1024)) { // Do nothing. } } cout.form("Try \"fstat -p %d\"\n", getpid()); cout.form("Ok! Go to Sleep. [%d sec]\n", atoi(argv[2])); sleep(atoi(argv[2])); return EX_OK; } //-------------------------------------------------------------------------- - To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message