Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Max handle for a process



Permlink Replies: 4 - Last Post: Dec 6, 2017 8:31 AM Last Post By: Christophe TAFF...
Christophe TAFF...

Posts: 7
Registered: 3/2/06
Max handle for a process
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 5, 2017 6:06 AM
Hi,
I have an application with 15 threads and 1 thread is used to write data in several file (about 20). This application runs all the time (24 h/ 24h). Sometime, when the thread cannot open a file, or cannot write in file already open.
When I follow the handles in task manager, the application manages about 245 handles. I have the impression as if the number of handle is superior to 250, I have this error on the files.
How many handle is possible to managed by a thread or by a process ?
Do you an idea to solve this radom problem ?
Platform used: C++ - Embarcadero XE2

Thank by advance for your answer
Alex Belo

Posts: 626
Registered: 10/8/06
Re: Max handle for a process
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 5, 2017 8:11 AM   in response to: Christophe TAFF... in response to: Christophe TAFF...
Christophe TAFFOUREAU wrote:

I have an application with 15 threads and 1 thread is used to write
data in several file (about 20). This application runs all the time
(24 h/ 24h). Sometime, when the thread cannot open a file, or cannot
write in file already open. When I follow the handles in task
manager, the application manages about 245 handles. I have the
impression as if the number of handle is superior to 250, I have this
error on the files. How many handle is possible to managed by a
thread or by a process ? Do you an idea to solve this radom problem
? Platform used: C++ - Embarcadero XE2

In RAD2007:

/* _nfile.h
Maximum number of open files
*/
...
#define NFILE 50

stdio.h:
...
/* Number of files that can be open simultaneously
*/
#if defined(__STDC__)
#define FOPEN_MAX (_NFILE_)
#else
#define FOPEN_MAX (_NFILE_)
#define SYS_OPEN (_NFILE_)
#endif

io.h:
#define HANDLE_MAX (_NFILE_)

What value you have in XE2?

_setmaxstdio
https://docs.microsoft.com/ru-ru/cpp/c-runtime-library/reference/setmaxstdio

But if Builder still has hardcoded limit then there is no such function
available in RTL I am afraid ...

--
Alex

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Max handle for a process
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 5, 2017 10:09 AM   in response to: Alex Belo in response to: Alex Belo
Alex Belo wrote:

/* _nfile.h
Maximum number of open files
*/
...
#define NFILE 50

That only applies to the C runtime file functions, like fopen(). It
does not apply to the Win32 API, or the Borland/Embarcadero RTL.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Max handle for a process
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 5, 2017 10:08 AM   in response to: Christophe TAFF... in response to: Christophe TAFF...
Christophe TAFFOUREAU wrote:

Sometime, when the thread cannot open a file, or cannot write in file
already open.

That is a pretty specific error. What permissions are you trying to
open the file with? What have you done to debug who has the file open
with conflicting permissions?

When I follow the handles in task manager, the application manages
about 245 handles.

Then you are likely not managing your handles correctly, such as not
closing them when you are done using them, etc. Use a tool like
SysInternal Process Explorer to see exactly what type of handles you
have open and what they refer to.

I have the impression as if the number of handle is superior to 250, I
have this error on the files.

That is not your problem.

How many handle is possible to managed by a thread or by a process ?

A LOT more than 250. You are basically limited only by available
resources.

--
Remy Lebeau (TeamB)
Christophe TAFF...

Posts: 7
Registered: 3/2/06
Re: Max handle for a process
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 6, 2017 8:31 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Christophe TAFFOUREAU wrote:

Sometime, when the thread cannot open a file, or cannot write in file
already open.

That is a pretty specific error. What permissions are you trying to
open the file with? What have you done to debug who has the file open
with conflicting permissions?

The files are opened with R/W permissions. A precision: The files are not present in the PC where running my softwrae, but it are written on another server connected by SAMBA link.
If this server is busy by another process which writting in files, can my process (present in another PC) lock ?


When I follow the handles in task manager, the application manages
about 245 handles.

Then you are likely not managing your handles correctly, such as not
closing them when you are done using them, etc. Use a tool like
SysInternal Process Explorer to see exactly what type of handles you
have open and what they refer to.

I have the impression as if the number of handle is superior to 250, I
have this error on the files.

That is not your problem.

How many handle is possible to managed by a thread or by a process ?

A LOT more than 250. You are basically limited only by available
resources.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02