🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
7 messages
7 total messages Started by Josef Halder Sat, 17 Nov 2007 11:02
detect how many files are open
#1058
Author: Josef Halder
Date: Sat, 17 Nov 2007 11:02
17 lines
1409 bytes
Hi,

is there a way to detect how many files are open at the moment?
My problem is when the program is running two weeks or longer without
restart then comes a point after that is not longer possible to open (to
read or to write) a file. After that point any attempt to open a file,
generates an error.
I belive there is a situation a file is not closed. But the program is very
complex so it's difficult to find out.

Example:
At various times during the program is running I open files with   FILE *f =
fopen("Filename.TXT","rt");
I read/write and after that I close with    fclose(f);

Thanks for help
Josef
Re: detect how many files are open
#1059
Author: Marc
Date: Sat, 17 Nov 2007 11:27
34 lines
2046 bytes
Josef

I had a similar situation and used the Windows performance monitor to track 
the open file handles. This pointed me to the moment when a handle was 
opened but not closed again.
Another thing that helped me in the past for those issues was the CodeGuard.

Rds
Marc


"Josef Halder" <no_spam@email.xxx> schrieb im Newsbeitrag 
news:473eca61$1@newsgroups.borland.com...
> Hi,
>
> is there a way to detect how many files are open at the moment?
> My problem is when the program is running two weeks or longer without
> restart then comes a point after that is not longer possible to open (to
> read or to write) a file. After that point any attempt to open a file,
> generates an error.
> I belive there is a situation a file is not closed. But the program is 
> very
> complex so it's difficult to find out.
>
> Example:
> At various times during the program is running I open files with   FILE *f 
> =
> fopen("Filename.TXT","rt");
> I read/write and after that I close with    fclose(f);
>
> Thanks for help
> Josef
>
> 
Re: detect how many files are open
#1061
Author: Josef Halder
Date: Sat, 17 Nov 2007 12:34
62 lines
2685 bytes
Hi Marc,

this error appears only at our customers. I don't mange to simulate this
special situation in the IDE.
Thats my problem.
So I can't use CodeGard. Or is there a way to use CodeGard outside the IDE?

With old MS DOS programs (long time ago) it was possible to detect how many
files are open.
The function flushall() resulted the count of open files.
But windows programs doesn't support this.

What is the Windows performance monitor?
How can I start it?

Thanks
Josef




"Marc" <info@mawnet.com> schrieb im Newsbeitrag
news:473ed068$1@newsgroups.borland.com...
> Josef
>
> I had a similar situation and used the Windows performance monitor to
track
> the open file handles. This pointed me to the moment when a handle was
> opened but not closed again.
> Another thing that helped me in the past for those issues was the
CodeGuard.
>
> Rds
> Marc
>
>
> "Josef Halder" <no_spam@email.xxx> schrieb im Newsbeitrag
> news:473eca61$1@newsgroups.borland.com...
> > Hi,
> >
> > is there a way to detect how many files are open at the moment?
> > My problem is when the program is running two weeks or longer without
> > restart then comes a point after that is not longer possible to open (to
> > read or to write) a file. After that point any attempt to open a file,
> > generates an error.
> > I belive there is a situation a file is not closed. But the program is
> > very
> > complex so it's difficult to find out.
> >
> > Example:
> > At various times during the program is running I open files with   FILE
*f
> > =
> > fopen("Filename.TXT","rt");
> > I read/write and after that I close with    fclose(f);
> >
> > Thanks for help
> > Josef
> >
> >
>
>
Re: detect how many files are open
#1062
Author: JohnC
Date: Sat, 17 Nov 2007 13:08
8 lines
1350 bytes
> So I can't use CodeGard. Or is there a way to use CodeGard outside the 
> IDE?

When the application is linked with Codeguard, Codeguard will generate a log 
file when the application terminates.
(It certainly gets generated and I think that is when it happens.)  There 
must be a way of reading this log file and interpreting the results.
John 
Re: detect how many files are open
#1064
Author: Ed Mulroy [TeamB]
Date: Sat, 17 Nov 2007 13:27
46 lines
2211 bytes
For FILE* style files you might try something like this:

----------------------
#include <stdio.h>

#ifdef __cplusplus
using std::FILE;
using std::_streams;
#endif

int NumFilesOpen()
    {
    FILE *fp = &_streams[0];
    int num_open = 0;

    for (int i = 0; i < _NFILE_; ++i, ++fp)
        if (fp->fd != -1)
            ++num_open;

    return num_open;
    }
----------------------

Just remember that three files are going to be open at all times, stdin, 
stdout and stdprn.

.  Ed

> Josef Halder wrote in message
> news:473eca61$1@newsgroups.borland.com...
> Hi,
>
> is there a way to detect how many files are open at the moment?
> My problem is when the program is running two weeks or longer without
> restart then comes a point after that is not longer possible to open (to
> read or to write) a file. After that point any attempt to open a file,
> generates an error.
> I belive there is a situation a file is not closed. But the program is 
> very
> complex so it's difficult to find out.
>
> Example:
> At various times during the program is running I open files with   FILE *f 
> =
> fopen("Filename.TXT","rt");
> I read/write and after that I close with    fclose(f);
Re: detect how many files are open
#1066
Author: Josef Halder
Date: Sat, 17 Nov 2007 14:04
59 lines
2519 bytes
perfect!
this is exactly what I need!

Thanks
Josef



"Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> schrieb im Newsbeitrag
news:473eec3e$1@newsgroups.borland.com...
> For FILE* style files you might try something like this:
>
> ----------------------
> #include <stdio.h>
>
> #ifdef __cplusplus
> using std::FILE;
> using std::_streams;
> #endif
>
> int NumFilesOpen()
>     {
>     FILE *fp = &_streams[0];
>     int num_open = 0;
>
>     for (int i = 0; i < _NFILE_; ++i, ++fp)
>         if (fp->fd != -1)
>             ++num_open;
>
>     return num_open;
>     }
> ----------------------
>
> Just remember that three files are going to be open at all times, stdin,
> stdout and stdprn.
>
> .  Ed
>
> > Josef Halder wrote in message
> > news:473eca61$1@newsgroups.borland.com...
> > Hi,
> >
> > is there a way to detect how many files are open at the moment?
> > My problem is when the program is running two weeks or longer without
> > restart then comes a point after that is not longer possible to open (to
> > read or to write) a file. After that point any attempt to open a file,
> > generates an error.
> > I belive there is a situation a file is not closed. But the program is
> > very
> > complex so it's difficult to find out.
> >
> > Example:
> > At various times during the program is running I open files with   FILE
*f
> > =
> > fopen("Filename.TXT","rt");
> > I read/write and after that I close with    fclose(f);
>
>
Re: detect how many files are open
#1068
Author: Marc
Date: Sat, 17 Nov 2007 15:02
80 lines
3181 bytes
> What is the Windows performance monitor?
> How can I start it?

Start->Einstellungen->Systemsteuerung->Verwaltung->Leistung

(I hope your Windows "speaks" German :-)


Rds
Marc

"Josef Halder" <no_spam@email.xxx> schrieb im Newsbeitrag 
news:473edfe8$1@newsgroups.borland.com...
> Hi Marc,
>
> this error appears only at our customers. I don't mange to simulate this
> special situation in the IDE.
> Thats my problem.
> So I can't use CodeGard. Or is there a way to use CodeGard outside the 
> IDE?
>
> With old MS DOS programs (long time ago) it was possible to detect how 
> many
> files are open.
> The function flushall() resulted the count of open files.
> But windows programs doesn't support this.
>
> What is the Windows performance monitor?
> How can I start it?
>
> Thanks
> Josef
>
>
>
>
> "Marc" <info@mawnet.com> schrieb im Newsbeitrag
> news:473ed068$1@newsgroups.borland.com...
>> Josef
>>
>> I had a similar situation and used the Windows performance monitor to
> track
>> the open file handles. This pointed me to the moment when a handle was
>> opened but not closed again.
>> Another thing that helped me in the past for those issues was the
> CodeGuard.
>>
>> Rds
>> Marc
>>
>>
>> "Josef Halder" <no_spam@email.xxx> schrieb im Newsbeitrag
>> news:473eca61$1@newsgroups.borland.com...
>> > Hi,
>> >
>> > is there a way to detect how many files are open at the moment?
>> > My problem is when the program is running two weeks or longer without
>> > restart then comes a point after that is not longer possible to open 
>> > (to
>> > read or to write) a file. After that point any attempt to open a file,
>> > generates an error.
>> > I belive there is a situation a file is not closed. But the program is
>> > very
>> > complex so it's difficult to find out.
>> >
>> > Example:
>> > At various times during the program is running I open files with   FILE
> *f
>> > =
>> > fopen("Filename.TXT","rt");
>> > I read/write and after that I close with    fclose(f);
>> >
>> > Thanks for help
>> > Josef
>> >
>> >
>>
>>
>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads